--melonloader.debug crashes debug build of Unity game on startup
TheCutter opened this issue ยท 10 comments
I'm trying to debug Terraforming Mars on Windows.
I turned the release build into a debug build with the help of this guide: https://github.com/dnSpy/dnSpy/wiki/Debugging-Unity-Games
But starting the game with the "--melonloader.debug" option now crashes on startup at:
"[21:20:50.698] [DEBUG] Creating Mono Domain..."
I'm trying to debug Terraforming Mars on Windows.
I turned the release build into a debug build with the help of this guide: https://github.com/dnSpy/dnSpy/wiki/Debugging-Unity-Games
But starting the game with the "--melonloader.debug" option now crashes on startup at:
"[21:20:50.698] [DEBUG] Creating Mono Domain..."
Mind posting the full log?
Also you don't have to replace any files to debug with MelonLoader.
It should handle creating the debug context for you when you use "--melonloader.debug" without modifying other files.
But without a debug build I'm not able to connect a debugger to unity with VS or dnSpy.
[21:20:50.627] [DEBUG] Initializing Mono...
[21:20:50.629] [DEBUG] Mono::BasePath = D:\Games\steamapps\common\Terraforming Mars\MonoBleedingEdge\EmbedRuntime
[21:20:50.629] [DEBUG] Mono::ManagedPath = D:\Games\steamapps\common\Terraforming Mars\TerraformingMars_Data\Managed
[21:20:50.630] [DEBUG] Mono::ConfigPath = D:\Games\steamapps\common\Terraforming Mars\MonoBleedingEdge\etc
[21:20:50.630] [DEBUG] Mono::IsOldMono = false
[21:20:50.631] ------------------------------
[21:20:50.631] MelonLoader v0.4.3 Open-Beta
[21:20:50.631] OS: Windows 10
[21:20:50.632] Hash Code: 10199571005256100975748575398505751559856525454574855561005057495297
[21:20:50.632] ------------------------------
[21:20:50.638] Name: Terraforming Mars
[21:20:50.638] Developer: LuckyHammers
[21:20:50.638] Unity Version: 2019.4.15
[21:20:50.639] Game Type: MonoBleedingEdge
[21:20:50.639] Game Arch: x64
[21:20:50.639] ------------------------------
[21:20:50.640] [DEBUG] Core::BasePath = D:\Games\steamapps\common\Terraforming Mars
[21:20:50.640] [DEBUG] Game::BasePath = D:\Games\steamapps\common\Terraforming Mars
[21:20:50.640] [DEBUG] Game::DataPath = D:\Games\steamapps\common\Terraforming Mars\TerraformingMars_Data
[21:20:50.641] [DEBUG] Game::ApplicationPath = D:\Games\steamapps\common\Terraforming Mars\TerraformingMars.exe
[21:20:50.641] [DEBUG] Initializing Analytics Blocker...
[21:20:50.641] [DEBUG] Initializing wsock32...
[21:20:50.642] [DEBUG] Initializing wsock32 Exports...
[21:20:50.643] [DEBUG] gethostbyname
[21:20:50.643] [DEBUG] Initializing ws2_32...
[21:20:50.643] [DEBUG] Initializing ws2_32 Exports...
[21:20:50.644] [DEBUG] getaddrinfo
[21:20:50.644] [DEBUG] Loading Mono Library...
[21:20:50.646] [DEBUG] Initializing Mono Exports...
[21:20:50.647] [DEBUG] mono_jit_init
[21:20:50.647] [DEBUG] mono_jit_parse_options
[21:20:50.648] [DEBUG] mono_thread_set_main
[21:20:50.649] [DEBUG] mono_thread_current
[21:20:50.649] [DEBUG] mono_add_internal_call
[21:20:50.654] [DEBUG] mono_lookup_internal_call
[21:20:50.655] [DEBUG] mono_runtime_invoke
[21:20:50.656] [DEBUG] mono_method_get_name
[21:20:50.657] [DEBUG] mono_domain_assembly_open
[21:20:50.657] [DEBUG] mono_assembly_get_image
[21:20:50.658] [DEBUG] mono_class_from_name
[21:20:50.659] [DEBUG] mono_class_get_method_from_name
[21:20:50.659] [DEBUG] mono_string_to_utf8
[21:20:50.660] [DEBUG] mono_string_new
[21:20:50.661] [DEBUG] mono_object_get_class
[21:20:50.662] [DEBUG] mono_property_get_get_method
[21:20:50.662] [DEBUG] mono_image_get_name
[21:20:50.663] [DEBUG] mono_debug_init
[21:20:50.664] [DEBUG] mono_debug_domain_create
[21:20:50.664] [DEBUG] mono_domain_set_config
[21:20:50.665] [DEBUG] mono_unity_get_unitytls_interface
[21:20:50.668] [DEBUG] mono_free
[21:20:50.669] [DEBUG] mono_object_to_string
[21:20:50.669] [DEBUG] mono_jit_init_version
[21:20:50.670] [DEBUG] Attaching Hooks to wsock32...
[21:20:50.671] [DEBUG] gethostbyname
[21:20:50.671] [DEBUG] Attaching Hooks to ws2_32...
[21:20:50.672] [DEBUG] getaddrinfo
[21:20:50.673] [DEBUG] Attaching Hook to mono_jit_init_version...
[21:20:50.697] [DEBUG] Detaching Hook from mono_jit_init_version...
[21:20:50.698] [DEBUG] Creating Mono Domain...
Before making it a debug build I was able to start with the --melonloader.debug command, but couldn't add a debugger to the running game.
https://github.com/LavaGang/MelonLoader/blob/master/Bootstrap/Managers/Mono.cpp#L399
MelonLoader runs the appropriate debug exports that those patched Mono libraries use.
This is why replacing files isn't needed because MelonLoader handles it at runtime.
Have you tried following the instructions on the Wiki and Readme without replacing files?
https://melonwiki.xyz/#/modders/debugging
Have you tried following the instructions on the Wiki and Readme without replacing files?
https://melonwiki.xyz/#/modders/debugging
Yes I have done it that way, but this doesn't give me a Unity Instance to connect the debugger to.
If I start the game from inside dnSpy or VS it starts, closes, Steam starts and starts the game again.
Maybe thats the problem!?
Have you tried following the instructions on the Wiki and Readme without replacing files?
https://melonwiki.xyz/#/modders/debuggingYes I have done it that way, but this doesn't give me a Unity Instance to connect the debugger to.
If I start the game from inside dnSpy or VS it starts, closes, Steam starts and starts the game again.
Maybe thats the problem!?
That could be seeing as you should have Steam already started when you try to launch a Steam Game.
Nevermind, I switched to BepInEx with debug build and everything works fine.
Umm ok?
Doesn't really help get to the bottom of the problem you are having with MelonLoader though.
As it seems it is an actual issue with debugging.
I did run into an issue a while back of steam asking are you sure you want to launch the program with the flags --melonloader.debug
when not launched directly through steam and then dnspy not being able to attach. Though that was a month or 2 ago, and I can't test right now.