Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better C# documentation #268

Open
Vixeliz opened this issue May 30, 2021 · 11 comments
Open

Better C# documentation #268

Vixeliz opened this issue May 30, 2021 · 11 comments

Comments

@Vixeliz
Copy link

Vixeliz commented May 30, 2021

Hello! Firstly thanks for the amazing module! But I find the documentation overall for me at least be hard to follow. Which is fine with gdscript since there are so many examples. But recently I have started trying to get into C# and am having a lot of trouble getting anything done. Perhaps even just a simple example of editing voxels in C# would be nice? If I can get the hang of it before anyone else does it I would love to contribute to either the docs or an example.

@Vixeliz
Copy link
Author

Vixeliz commented May 30, 2021

So I got a little further I think but I get a few errors in console:

E 0:00:01.425   VoxelTool::_get_voxel: Not implemented
  <C++ Source>  modules\voxel\edition\voxel_tool.cpp:133 @ VoxelTool::_get_voxel()
  <Stack Trace> :0 @ UInt64 Godot.NativeCalls.godot_icall_1_1111(IntPtr , IntPtr , Godot.Vector3& )()
                VoxelTool.cs:244 @ UInt64 Godot.VoxelTool.GetVoxel(Godot.Vector3 )()
                VoxelTerrain.cs:15 @ void VoxelTerrain._Ready()()
E 0:00:01.428   VoxelTool::is_area_editable: Not implemented
  <C++ Source>  modules\voxel\edition\voxel_tool.cpp:246 @ VoxelTool::is_area_editable()
  <Stack Trace> :0 @ void Godot.NativeCalls.godot_icall_2_1112(IntPtr , IntPtr , Godot.Vector3& , UInt64 )()
                VoxelTool.cs:262 @ void Godot.VoxelTool.SetVoxel(Godot.Vector3 , UInt64 )()
                VoxelTerrain.cs:16 @ void VoxelTerrain._Ready()()
E 0:00:01.430   VoxelTool::_get_voxel: Not implemented
  <C++ Source>  modules\voxel\edition\voxel_tool.cpp:133 @ VoxelTool::_get_voxel()
  <Stack Trace> :0 @ UInt64 Godot.NativeCalls.godot_icall_1_1111(IntPtr , IntPtr , Godot.Vector3& )()
                VoxelTool.cs:244 @ UInt64 Godot.VoxelTool.GetVoxel(Godot.Vector3 )()
                VoxelTerrain.cs:17 @ void VoxelTerrain._Ready()()

@Zylann
Copy link
Owner

Zylann commented May 30, 2021

Duplicating every example and every docs in "C# mode" is not possible for me atm. Both in terms of available time since I don't regularly use C# in Godot, and also technically because my documentation system cannot have C#/GDScript tabs like Godot docs are doing. So for now you'll have to translate naming conventions from snake_case to PascalCase yourself when reading the API or code samples.

The errors you are getting are very strange... I wonder what on earth C# is doing here, but assuming you use the VoxelTerrain class, when you use VoxelTerrain.get_voxel_tool(), it gives you a VoxelToolTerrain.

The base class binds get_voxel to _b_get_voxel():

ClassDB::bind_method(D_METHOD("get_voxel", "pos"), &VoxelTool::_b_get_voxel);

Which corresponds to this implementation:

return get_voxel(Vector3i::from_floored(pos));

Which in turn goes to _get_voxel:

uint64_t VoxelTool::get_voxel(Vector3i pos) const {

_get_voxel is virtual, so it may call VoxelToolTerrain._get_voxel():

uint64_t VoxelToolTerrain::_get_voxel(Vector3i pos) const {

Which is implemented.
So I have no idea how you even get these errors Oo
Which version of the module are you using?

@Vixeliz
Copy link
Author

Vixeliz commented May 30, 2021

I managed to get the errors figured out I was being quite stupid. I still think it would be nice to keep this issue open even though you don't have the time to work on C# documentation/examples. I personally after I am more comfortable with C# would like to contribute a few C# examples and maybe some code examples to the docs if that is something you would be willing to accept?

@Zylann
Copy link
Owner

Zylann commented May 30, 2021

I'm not against C# examples, but the problem is, I have no idea how to present that properly in the docs next to GDScript examples.

@Vixeliz
Copy link
Author

Vixeliz commented May 31, 2021

Perhaps everywhere there is a script or a code sample just have them one above each other with a subtitle that says GDScript: and CSharp: accordingly?

@Vixeliz
Copy link
Author

Vixeliz commented May 31, 2021

So I got editing the terrain working I have moved onto to trying to get a generator script working. It works in editor if I temporarily turn on run stream in editor(then turn off after it is done generating) but if I try to actually launch the game it just crashes.

using Godot;
using System;

[Tool]
public class WorldGenerator : VoxelGeneratorScript
{

  public static readonly VoxelBuffer.ChannelId BlockChannel = VoxelBuffer.ChannelId.ChannelType;
  public override int _GetUsedChannelsMask() {
    return 1 << (int)BlockChannel;
  }
  public override void _GenerateBlock(VoxelBuffer outBuffer, Vector3 originInVoxels, int lod) {
    if(lod != 0)
      return;

    var ch = (uint)BlockChannel;

    var id = (uint)1;

    if(originInVoxels.y < 0)
      outBuffer.Fill(id, ch);

    if(originInVoxels.x == originInVoxels.z && originInVoxels.y < 1)
      outBuffer.Fill(id, ch);
  
  }
}

This is the code ^^^^

and here is the error's in console:

ERROR: GDMonoLog::mono_log_callback: ERROR: GDMonoLog::mono_log_callback: Mono: FATAL ERROR '* Assertion at ..\mono\mini\debugger-agent.c:4175, condition `!tls' not met                                                                         (in domain , error)', ABORTING! Logfile: 'C:\Users\muevo\AppData\Roaming/Godot/mono/mono_logs/2021-05-30_23.53.24_8644.log'.                                                                                                                   Mono: FATAL ERROR '* Assertion at ..\mono\mini\debugger-agent.c:4175, condition `!tls' not met                           (in domain , error)', ABORTING! Logfile: 'C:\Users\muevo\AppData\Roaming/Godot/mono/mono_logs/2021-05-30_23.53.24_8644.log'.                                                                                                                      At:    At: modules\mono\mono_gd\gd_mono_log.cpp:93       

@Zylann
Copy link
Owner

Zylann commented May 31, 2021

Does the same code crashes in GDScript? I have absolutely no clue why it crashes here, other than C# "still being in beta stage" in Godot (not sure how tested multithreading is).

The only issue I could find with such an error seems unrelated: godotengine/godot#45911
Which makes me wonder if that error has any relation to your actual problem. Maybe it's rather a problem with the debugger. Is this really the only error you get?

@Vixeliz
Copy link
Author

Vixeliz commented May 31, 2021

Yes that seems to be the only error I get when using c#. The code does not crash with gdscript. I would prefer not to use gdscript due to performance. Is gdnative another option worse case? I would still prefer to use c# if possible but as a backup option gdnative I would be ok with. Furthermore should I open up an issue on the godot github page? Or is this related to godot_voxel more?

Edit:
Also out of curiosity why would it run fine in the editor but not after exporting/running the project?

@Zylann
Copy link
Owner

Zylann commented May 31, 2021

Is gdnative another option worse case?

Yes, if you absolutely crave about performance at the cost of some of your sanity

should I open up an issue on the godot github page? Or is this related to godot_voxel more?

If you can reproduce this by spinning up a thread in GDScript and calling a C# script from it, maybe. At least that's what my module does, it calls your script from a Godot Thread.

Also out of curiosity why would it run fine in the editor but not after exporting/running the project?

My guess is that when the game runs, Godot also tries to attach with its own debugger, and I think it does not support threading properly?

@Vixeliz
Copy link
Author

Vixeliz commented May 31, 2021

Ok I reproduced with a simple script that just calls a function from C# that prints "hello" and it crashes with the same error so I will open an issue on the godot github

Edit:
Here is the link to track if you are interested:
godotengine/godot#49230

@Vixeliz
Copy link
Author

Vixeliz commented Jun 1, 2021

I think you are onto something with debugging compiling for release it runs fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants