WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
361 stars 27 forks source link

Fix mono glue generation #165

Closed Trey2k closed 10 months ago

Trey2k commented 10 months ago

A quick fix for mono glue generation mistake discovered in #164, we generated it but never built it.

michieal commented 10 months ago

Well, it didn't error out, but...

/.../test.csproj(0,0): Unable to find package Godot.NET.Sdk with version (= 4.1.2-rc)

and

/.../test.csproj(0,0): The SDK 'Godot.NET.Sdk/4.1.2-rc' specified could not be found.

Occurs, when building the project. Do I need to update my project?

Trey2k commented 10 months ago

Well, it didn't error out, but...

/.../test.csproj(0,0): Unable to find package Godot.NET.Sdk with version (= 4.1.2-rc)

and

/.../test.csproj(0,0): The SDK 'Godot.NET.Sdk/4.1.2-rc' specified could not be found.

Occurs, when building the project. Do I need to update my project?

I am unsure about this to be honest. I am not a c# user myself. You could try deleteing cache, IE the .godot folder. And or checking the project file to see if it specifies a version that can be updated.

michieal commented 10 months ago

I see. Well, I just looked, and the specified Godot Sdk that the engine specifies (4.1.2 rc) doesn't exist as a nuget package. The nuget package tells the compiler what namespaces to import, and the class definitions... Sorta like a huge header file that comprises the entirety of the sdk. (A .h file full of externs, and namespaces, etc..)

The editor updated the sdk to the "new" sdk, instead of using the old one. But, the project file won't load because the package specified for the sdk doesn't exist on the nuget repository. When I enabled pre-release packages, the only one to show up was the Godot-SDK 4.2-dev-06.

So... hmmn. question. Your build of the editor should have a spot where it targets an sdk... can you look there to see? Or, maybe make a nuget package, and place that into the release?

I'll do some digging.

michieal commented 10 months ago

Okay, so it looks like changing it to rc.1 works.

<Project Sdk="Godot.NET.Sdk/4.1.2-rc.1">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

Works with this. (things at least compile.) Though, any new project, people will need to go in and manually change that. Edit... I found where the nuget nupkg was stored. I just had to add it into the sources list, for Rider, and it allows it to be built.

michieal commented 10 months ago

I spoke too soon. Things sorta work... I got all of this when I ran the project.

Godot log in the app_userdata for the project:

Godot Engine v4.1.stable.mono.luaAPI.970459615 - https://godotengine.org
Vulkan API 1.3.240 - Forward+ - Using Vulkan Device #0: AMD - Radeon RX 5700 XT

USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_get_instance_binding_managed (modules/mono/glue/runtime_interop.cpp:241)
USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_instance_binding_create_managed (modules/mono/glue/runtime_interop.cpp:254)
USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_get_instance_binding_managed (modules/mono/glue/runtime_interop.cpp:241)
USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_instance_binding_create_managed (modules/mono/glue/runtime_interop.cpp:254)
USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_get_instance_binding_managed (modules/mono/glue/runtime_interop.cpp:241)
USER ERROR: Parameter "strong_gchandle.value" is null.
   at: setup_csharp_script_binding (modules/mono/csharp_script.cpp:1286)
USER ERROR: Condition "!script_binding.inited" is true. Returning: { nullptr }
   at: godotsharp_internal_unmanaged_instance_binding_create_managed (modules/mono/glue/runtime_interop.cpp:254)

...

USER ERROR: BUG: Unreferenced static string to 0: luminance_buffers
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: rb_ssil
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: reflection
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: rb_ssao
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: final
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: blur_0
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: back_depth
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: normal_roughnesss
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: Fog
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: VRS
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: sdfgi
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: RaycastOcclusionCullUpdateCamera
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: Physics3DConstraintSolveIslands
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: Physics3DConstraintSetup
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: Physics2DConstraintSolveIslands
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: Physics2DConstraintSetup
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: _compression
   at: unref (core/string/string_name.cpp:129)
USER ERROR: BUG: Unreferenced static string to 0: ShaderCompilation
   at: unref (core/string/string_name.cpp:129)
USER ERROR: Pages in use exist at exit in PagedAllocator: N7Variant5Pools11BucketLargeE
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
USER ERROR: Pages in use exist at exit in PagedAllocator: N7Variant5Pools12BucketMediumE
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
USER ERROR: Pages in use exist at exit in PagedAllocator: N7Variant5Pools11BucketSmallE
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
USER ERROR: BUG: Unreferenced static string to 0: animation_list_changed
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: caches_cleared
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: AudioStreamPlaybackMP3
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: GodotPhysicsDirectSpaceState2D
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: GodotPhysicsDirectSpaceState3D
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: interface_added
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: frame_pre_draw
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: frame_post_draw
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: SceneReplicationInterface
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: process_frame
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: physics_frame
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: SceneCacheInterface
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: RenderBufferDataForwardClustered
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: menu_changed
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: SceneRPCInterface
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: fallback_changed
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: RenderBuffersGI
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: child_exiting_tree
   at: unref (core/string/string_name.cpp:131)
USER ERROR: BUG: Unreferenced static string to 0: child_entered_tree
   at: unref (core/string/string_name.cpp:131)
  Cannot open file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed to read file: '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Cannot load C# script file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed loading resource: /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs. Make sure resources have been imported by opening the project in the editor at least once.
  Cannot open file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed to read file: '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Cannot load C# script file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed loading resource: /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs. Make sure resources have been imported by opening the project in the editor at least once.
  Cannot open file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed to read file: '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Cannot load C# script file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs'.
  Failed loading resource: /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.UnmanagedCallbacksGenerator/Godot.NativeInterop.NativeFuncs.generated.cs. Make sure resources have been imported by opening the project in the editor at least once.
  Cannot open file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs'.
  Failed to read file: '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs'.
  Cannot load C# script file '/home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs'.
  Failed loading resource: /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs. Make sure resources have been imported by opening the project in the editor at least once.

I'm not sure where exactly the full logs are? I think the above covers what shows up in the debugger, if not and you know where they are stored, let me know, and I'll paste them in here.

Logs for these errors: image

It looks like it's not making the Native Binds for the C# code.

Godot.GodotObject+NativeMethodBindNotFoundException: Unable to find the native method bind. (Method 'Camera3D.get_camera_projection')
   at Godot.GodotObject.ClassDB_get_method(StringName type, StringName method) in /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 219
   at Godot.Camera3D..cctor() in /home/trey2k/Development/WeaselGames/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Camera3D.cs:line 454

^ one of many.

Trey2k commented 10 months ago

@michieal I am unable to reproduce this issue, something may of gone wrong while building it on my end. But i downloaded latest mono build from actions and was able to run a hello world c# project. Could you please try again with https://github.com/WeaselGames/godot_luaAPI/suites/16855092579/artifacts/962905802 and let me know if you are still having issues?

Trey2k commented 10 months ago

Okay, so it looks like changing it to rc.1 works.

<Project Sdk="Godot.NET.Sdk/4.1.2-rc.1">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

Works with this. (things at least compile.) Though, any new project, people will need to go in and manually change that. Edit... I found where the nuget nupkg was stored. I just had to add it into the sources list, for Rider, and it allows it to be built.

Also when createing a new project with this build the contents of this file are

<Project Sdk="Godot.NET.Sdk/4.1.0">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>
Trey2k commented 10 months ago

Okay, I do not think it actually built. I think whats happening for me is since its using a nuget package its getting the official godot nuget package. Not sure how we could for it to use the local version.

Trey2k commented 10 months ago

Okay @michieal, I have gotten mono to work properly now. There is some extra steps for you after downloading. I have added a mono_instructions.txt to the zip with the needed steps. If you can confirm this also works for you we will get it merged and update releases https://github.com/WeaselGames/godot_luaAPI/suites/16882169777/artifacts/964541199

image

using Godot;

using System;

public partial class Node2D : Godot.Node2D
{
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        GD.Print("Hello from C#");
        LuaApi lua = new LuaApi();
        lua.DoString("print(\"Hello from Lua\")");
    }
}
michieal commented 10 months ago

Okay, I'd say that this is ready to be merged.

Godot Engine v4.1.stable.mono.luaAPI.970459615 - https://godotengine.org
Vulkan API 1.3.240 - Forward+ - Using Vulkan Device #0: AMD - Radeon RX 5700 XT

System Start.
Hello from C#
Hello from Lua

It worked in both the recreated sample project, and in the project that I have been working on. The above is from the project that I have been working on... so, the System Start. is mine.

For the already existing project, I had to do a dotnet restore /path/to/myproject/myproject.csproj -f command, and everything worked well. (I did go in and change the sdk version in the project file to not be 4.1.2-rc though, but others shouldn't have to do that.

And, the best part is that there are no errors! 😃

One last thing, the export templates - might want to have a small file saying how to install them, for people not exactly used to the Godot system yet.

Thank you for fixing this, and epic work!

Trey2k commented 10 months ago

One last thing, the export templates - might want to have a small file saying how to install them, for people not exactly used to the Godot system yet.

This would probably be a good idea. I would need to decide how to tell people to do it. The zip we provide can be used a .tpz for importing default templates. Sadly godot does not add the build name or extra suffix to the version, so templates would conflict with the base editor in this case. The other option is to link the specific template in the export profile. Which is probably the better option.

Documentation always needs improvement haha

michieal commented 10 months ago

One last thing, the export templates - might want to have a small file saying how to install them, for people not exactly used to the Godot system yet.

This would probably be a good idea. I would need to decide how to tell people to do it. The zip we provide can be used a .tpz for importing default templates. Sadly godot does not add the build name or extra suffix to the version, so templates would conflict with the base editor in this case. The other option is to link the specific template in the export profile. Which is probably the better option.

Well, considering that I will need to know... As I am still very new to the Godot ecosystem. I guess, though, I can try digging around and see what I can come up with. Also, will the templates need to be updated? (Not sure how they work in comparison to the editor itself.) Also, I would go for the simplest instruction set, as a lot of windows users are used to "Install it, and it just works".

Documentation always needs improvement haha

lol, I feel that.

Trey2k commented 10 months ago

Well, considering that I will need to know... As I am still very new to the Godot ecosystem. I guess, though, I can try digging around and see what I can come up with. Also, will the templates need to be updated? (Not sure how they work in comparison to the editor itself.) Also, I would go for the simplest instruction set, as a lot of windows users are used to "Install it, and it just works".

I can give you a quick summery as I won't get to documentation for a little bit still. So the templates them selfs is just the godot engine compiled for a specific platform without the editor compiled with it. On exporting your game godot gives several options like packing the game assets into the template or creating a .pck file with your assets. These assets include anything from scripts to textures. The template is what ultimately become the executable for your game.

Now on how to use them, under releases we have 2 export template options. export-templates if for the normal engine builds without mono. These support all platforms. Then export-templates-mono is of course for mono. Since godot c# has low platform support right now. These only support Linux, windows and macos.

Inside the zip files you will see executables for each platform and architecture that is supported. There will be 2 for each supported combination, release and debug. Debug templates are to allow you to debug the exported project using godot debugging tools still. Release has that all stripped out to optimize the final release build.

When creating the export profile in the editor, it has you select the platform and architecture. To make use of our templates you then most set the file path for both the debug and release templates.

Edit: To answer if they need to be updated, the answer is yes. Anytime your editor is updated if you want the engine and module functionality to be updated for the final export you will need to download the corresponding template for the release version.

michieal commented 10 months ago

I can give you a quick summery as I won't get to documentation for a little bit still.

I figured, and that works. I'll make a document (or update the ReadMe) for the Mono steps. I think that this should be in there too. (I'm used to making documentation for the programs that I write, so it shouldn't be hard.) Also, is there a screenshots dir so that I can put images into the documentation?

So the templates themselves is just the Godot engine compiled for a specific platform without the editor compiled with it. On exporting your game Godot gives several options like packing the game assets into the template or creating a .pck file with your assets. These assets include anything from scripts to textures. The template is what ultimately become the executable for your game.

So, I need to grab those templates then. I only see the non-mono templates in the list here. (Web, iOS, Android.) Will there be a template pack or zip?

Now on how to use them, under releases we have 2 export template options. export-templates if for the normal engine builds without mono. These support all platforms. Then export-templates-mono is of course for mono. Since Godot c# has low platform support right now. These only support Linux, Windows and MacOS.

Right. "In da future..." lol.

Inside the zip files you will see executables for each platform and architecture that is supported. There will be 2 for each supported combination, release and debug. Debug templates are to allow you to debug the exported project using Godot debugging tools still. Release has that all stripped out to optimize the final release build.

Cool. That makes it easier.

When creating the export profile in the editor, it has you select the platform and architecture. To make use of our templates you then must set the file path for both the debug and release templates.

Okay. Can do.

Edit: To answer if they need to be updated, the answer is yes. Anytime your editor is updated if you want the engine and module functionality to be updated for the final export you will need to download the corresponding template for the release version.

I see, then I need to get the updated ones for this PR's release.

Trey2k commented 10 months ago

is there a screenshots dir so that I can put images into the documentation?

No, but one could be added under the .github folder.

So, I need to grab those templates then. I only see the non-mono templates in the list here. (Web, iOS, Android.) Will there be a template pack or zip?

Im a bit confused by what you mean here, none of these platforms currently support c#. Also the templates are in a zip archive.

I see, then I need to get the updated ones for this PR's release.

And actually the current export templates should work for you. This PR will likely not be a new release as all that changed is how we generate the glue. The editor and template binaries them selfsame should he unmodified. https://github.com/WeaselGames/godot_luaAPI/releases/download/v2.1-beta6/export-templates-mono.zip

michieal commented 10 months ago

is there a screenshots dir so that I can put images into the documentation?

No, but one could be added under the .github folder.

Okay, cool. When you merge this, I will fork it and make some documentation.

So, I need to grab those templates then. I only see the non-mono templates in the list here. (Web, iOS, Android.) Will there be a template pack or zip?

Im a bit confused by what you mean here, none of these platforms currently support c#. Also the templates are in a zip archive.

I was looking at the files that have the tests going, in this PR.

I see, then I need to get the updated ones for this PR's release.

And actually the current export templates should work for you. This PR will likely not be a new release as all that changed is how we generate the glue. The editor and template binaries them selfsame should he unmodified. https://github.com/WeaselGames/godot_luaAPI/releases/download/v2.1-beta6/export-templates-mono.zip

I just downloaded these. I did notice that there aren't any debug templates that are .x86_64, is this intentional? I mean, there's release templates for it, just the debug one is .x86_32.

Trey2k commented 10 months ago

I just downloaded these. I did notice that there aren't any debug templates that are .x86_64, is this intentional? I mean, there's release templates for it, just the debug one is .x86_32.

That sounds like a mistake, I will look into that tomorrow.

michieal commented 10 months ago

Understood. thank you.