godotengine / godot

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

Throwing a custom exception type defined in a dynamically loaded assembly crashes Godot. #18029

Closed PJB3005 closed 6 years ago

PJB3005 commented 6 years ago

Godot version: 7ca2e73dea59a2e0683253e73b9b549d749e12f9

OS/device including version: Windows 10 Pro 64-bit

Issue description: If you throw an exception type defined in a dynamically loaded assembly (that is, the assembly is loaded at runtime with say Assembly.LoadFrom), Godot will crash trying to handle the exception.

Unhandled Exception:
boo.DerperException: Exception of type 'boo.DerperException' was thrown.
  at ValueTupleFail._Ready () [0x0001e] in <4e356e85745e42e283f654b5e956ca85>:0
CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] Map<StringName,GDMonoProperty * __ptr64,Comparator<StringName>,DefaultAllocator>::find (f:\documents\pie\ss13 repos\godot\core\map.h:533)
[1] GDMonoClass::get_property (f:\documents\pie\ss13 repos\godot\modules\mono\mono_gd\gd_mono_class.cpp:361)
[2] GDMonoUtils::print_unhandled_exception (f:\documents\pie\ss13 repos\godot\modules\mono\mono_gd\gd_mono_utils.cpp:463)
[3] GDMonoUtils::print_unhandled_exception (f:\documents\pie\ss13 repos\godot\modules\mono\mono_gd\gd_mono_utils.cpp:415)
[4] GDMonoMethod::invoke (f:\documents\pie\ss13 repos\godot\modules\mono\mono_gd\gd_mono_method.cpp:132)
[5] CSharpInstance::_call_multilevel (f:\documents\pie\ss13 repos\godot\modules\mono\csharp_script.cpp:1218)
[6] CSharpInstance::call_multilevel (f:\documents\pie\ss13 repos\godot\modules\mono\csharp_script.cpp:1207)
[7] CSharpInstance::call_multilevel_reversed (f:\documents\pie\ss13 repos\godot\modules\mono\csharp_script.cpp:1230)
[8] Node::_notification (f:\documents\pie\ss13 repos\godot\scene\main\node.cpp:141)
[9] Node::_notificationv (f:\documents\pie\ss13 repos\godot\scene\main\node.h:46)
[10] Object::notification (f:\documents\pie\ss13 repos\godot\core\object.cpp:926)
[11] Node::_propagate_ready (f:\documents\pie\ss13 repos\godot\scene\main\node.cpp:184)
[12] Node::_propagate_ready (f:\documents\pie\ss13 repos\godot\scene\main\node.cpp:178)
[13] Node::_set_tree (f:\documents\pie\ss13 repos\godot\scene\main\node.cpp:2665)
[14] SceneTree::init (f:\documents\pie\ss13 repos\godot\scene\main\scene_tree.cpp:445)
[15] OS_Windows::run (f:\documents\pie\ss13 repos\godot\platform\windows\os_windows.cpp:2354)
[16] widechar_main (f:\documents\pie\ss13 repos\godot\platform\windows\godot_win.cpp:150)
[17] _main (f:\documents\pie\ss13 repos\godot\platform\windows\godot_win.cpp:172)
[18] main (f:\documents\pie\ss13 repos\godot\platform\windows\godot_win.cpp:184)
[19] __scrt_common_main_seh (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283)
[20] BaseThreadInitThunk
-- END OF BACKTRACE --

Steps to reproduce:

  1. Make a C# project.
  2. Make another project defining a simple exception type like say FooException.
  3. Put the following code in your main project:
    var asm = Assembly.LoadFrom("../path/to/assembly/goes/here.dll");
    var type = asm.GetType("FooException");
    throw (Exception)Activator.CreateInstance(type);
  4. Enjoy the fireworks.

Minimal reproduction project:

CustomExceptionLoadFrom.zip

PJB3005 commented 6 years ago

So this issue only happens if the assembly is loaded in such a way that the assembly search hook didn't catch it. One such a way is Assembly.LoadFrom("../path/to/assembly/goes/here.dll"), but y'know.

I'm gonna try to fix it myself.