Debugging Native Code Crashes in .NET Hosted Service Startup
Recently I ran across an interesting bug while adding an inventory system to Sovereign Engine. The client was crashing early during startup due to a segmentation fault, suggesting that there was a problem with how I was calling native code.
Firing up the client in gdb confirmed that the crash was due to native code:
(gdb) bt
#0 0x00007fbeac67413e in ImGui::GetFontSize() () from [...]/runtimes/linux-x64/native/cimgui.so
#1 0x00007fff7b768b44 in ?? ()
#2 0x000000000cabbc0c in ?? ()
#3 0x00007ffff76d2ef8 in ?? () from /usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.6/libcoreclr.so
#4 0x00007fffffffa988 in ?? ()
#5 0x0000000000000000 in ?? ()
Okay, so it looks like the client is crashing because of a segfault that happens when we call ImGui::GetFontSize(). Good news, we know what the offending call is. Bad news, it’s one of the most common native calls in the client and doesn’t do much to help us narrow down a root cause.