godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.83k stars 20.95k forks source link

Custom build is throwing an error on the Android platform: The type initializer for 'Godot.Viewport' threw an exception. #95933

Closed TrifingZW closed 1 month ago

TrifingZW commented 1 month ago

Tested versions

4.3.stable

System information

Android 14 - Godot v4.3.stable - OpenGL API OpenGL ES 3.2 V@0676.46 (GIT@73b5dd1032, I3166dd7455, 1695727537) (Date:09/26/23) - Compatibility - Using Device: Qualcomm - Adreno (TM) 720

Issue description

The build works fine on Windows using the same build configuration, but when using the Window node and its children on the Android platform, it throws the following error:

2024-08-22 13:26:56.718 31893-7884 godot com.trifingzw.emodule E USER ERROR: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'Godot.Viewport' threw an exception.
---> Godot.GodotObject+NativeMethodBindNotFoundException: Unable to find the native method bind. (Method 'Viewport.set_world_3d')
at Godot.GodotObject.ClassDB_get_method_with_compatibility(StringName type, StringName method, UInt64 hash)
at Godot.Viewport..cctor()
--- End of inner exception stack trace ---
at Godot.Window..ctor(Boolean memoryOwn)
at Godot.AcceptDialog..ctor(Boolean memoryOwn)
at Godot.AcceptDialog..ctor()
at BtlEditor.MainScreen.Scripts.LoadWindow..ctor()
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeConstructorWithoutAlloc(Object obj, Boolean wrapInTargetInvocationException)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseIn
2024-08-22 13:26:56.718 31893-7884 godot com.trifingzw.emodule E at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (:0)

custom.py:

target = "template_release"
platform = "windows"
arch = "x86_64"

debug_symbols = "no"
lto = "full"
production = "yes"
optimize = "speed"
module_mono_enabled = "yes"
disable_3d = "yes"  # 禁用所有3D相关功能
openxr = "no"  # 不需要XR
extra_suffix = "BtlEditor"
minizip = "no"  # 不需要压缩支持
opengl3 = "yes"  # opengl3
vulkan = "no"  # vulkan
use_llvm = "yes" # lvvm优化
deprecated = "yes" #关闭兼容代码
build_profile = "osos.build" #构建配置

module_astcenc_enabled = "no"  # ASTC纹理压缩
module_basis_universal_enabled = "no"  # Basis Universal纹理压缩
module_bmp_enabled = "no"  # BMP图像格式
module_camera_enabled = "yes"  # 摄像头支持
module_csg_enabled = "no"  # Constructive Solid Geometry (CSG)
module_cvtt_enabled = "no"  # Crunch纹理压缩
module_dds_enabled = "no"  # DDS纹理格式
module_enet_enabled = "no"  # ENet网络库
module_etcpak_enabled = "no"  # ETC纹理压缩
module_fbx_enabled = "no"  # FBX导入
module_freetype_enabled = "yes"  # FreeType字体渲染(保留,因为与3D无关)
module_gdscript_enabled = "no"  # GDScript支持
module_glslang_enabled = "yes"  # GLSL编译器
module_gltf_enabled = "no"  # GLTF导入
module_gridmap_enabled = "no"  # GridMap支持
module_hdr_enabled = "no"  # HDR图像支持
module_interactive_music_enabled = "no"  # 互动音乐模块(保留,因为与3D无关)
module_jpg_enabled = "no"  # JPG图像格式(保留,因为与3D无关)
module_jsonrpc_enabled = "no"  # JSON-RPC支持
module_ktx_enabled = "no"  # KTX纹理格式
module_lightmapper_rd_enabled = "no"  # 光照贴图(Lightmapper)
module_mbedtls_enabled = "no"  # mbedTLS库
module_meshoptimizer_enabled = "no"  # Mesh优化
module_minimp3_enabled = "no"  # MiniMP3库
minimp3_extra_formats = "no"  # MiniMP3额外格式
module_mobile_vr_enabled = "no"  # 移动VR支持
module_msdfgen_enabled = "yes"  # MSDF生成器
module_multiplayer_enabled = "no"  # 多人游戏支持
module_navigation_enabled = "no"  # 导航网格
module_noise_enabled = "no"  # 噪声生成
module_ogg_enabled = "no"  # OGG音频格式(保留,因为与3D无关)
module_openxr_enabled = "no"  # OpenXR支持
module_raycast_enabled = "no"  # 射线投射
module_regex_enabled = "no"  # 正则表达式支持
module_squish_enabled = "no"  # Squish纹理压缩
module_svg_enabled = "yes"  # SVG图像格式(保留,因为与3D无关)
module_tga_enabled = "no"  # TGA图像格式
module_theora_enabled = "no"  # Theora视频格式
module_tinyexr_enabled = "no"  # TinyEXR库
module_upnp_enabled = "no"  # UPNP支持
module_vhacd_enabled = "no"  # V-HACD(体积分解)
module_vorbis_enabled = "no"  # Vorbis音频格式
module_webp_enabled = "yes"  # WebP图像格式(保留,因为与3D无关)
module_webrtc_enabled = "no"  # WebRTC支持
module_websocket_enabled = "no"  # WebSocket支持
module_webxr_enabled = "no"  # WebXR支持
module_xatlas_unwrap_enabled = "no"  # XAtlas展开算法
module_zip_enabled = "no"  # ZIP压缩支持
module_text_server_adv_enabled= "no"
module_text_server_fb_enabled = "yes"

Steps to reproduce

No Steps to reproduce

Minimal reproduction project (MRP)

No MRP

raulsntos commented 1 month ago

It looks like the C# code is unable to find the method Viewport.set_world_3d. According to the custom.py you provided, you are building with 3D disabled, which means this method won't be registered in ClassDB.

https://github.com/godotengine/godot/blob/568589c9d8c763bfb3a4348174d53b42d7c59f21/scene/main/viewport.cpp#L4776-L4777

When using a custom build of the engine, make sure that the C# bindings you use match the same build configuration. Otherwise the C# bindings may contain methods that are not available in your custom build or other discrepancies.

To do this build the editor with the same build configuration you use for the template and then use it to generate the C# glue with --generate-mono-glue. Then, build the C# assemblies with build_assemblies.py and use the built packages in your C# project. See the Compiling with .NET documentation for a more detailed explanation of these steps.