Skip to content

Segfault in destructor at exit when compiling as a shared library #80

@marty-fly

Description

@marty-fly

This appeared somewhere in the zig-0.15 and imgui 1.92 upgrade. It didn't occur with 0.14. I don't get this error if I'm linking my program as a static library, and appears if I link it as a shared lib (it doesn't make a difference if I link zgui itself as shared or not).

I suspect this has something to do with issue #79. What happens is that some C++ object is still alive at program exit and it calls the destructor. It tries to call gui.zguiMemFree but that doesn't exist anymore, as zgui has already been deinitialized. Fixing that leak might fix this as well, but maybe zgui should also reset the memfree callback when deinitializing for cases like these.

Backtrace from gdb:

#0  0x00007ffff6e2e6d0 in ?? ()
#1  0x00007ffff70c3883 in ImGui::MemFree (ptr=0x7fffed520280) at /home/user/data/dev/game/thirdparty/zgui/libs/imgui/imgui.cpp:5027
#2  0x00007ffff71d10d8 in ImVector<ImGui_ImplGlfw_WindowToContext>::~ImVector (this=0x7ffff7216070 <g_ContextMap>) at /home/user/data/dev/game/thirdparty/zgui/libs/imgui/imgui.h:2251
#3  0x00007ffff7d03261 in __run_exit_handlers (status=0, listp=0x7ffff7ea8680 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at ./stdlib/exit.c:108
#4  0x00007ffff7d0331a in __GI_exit (status=<optimized out>) at ./stdlib/exit.c:138
#5  0x00007ffff7cead6f in __libc_start_call_main (main=main@entry=0x113d560 <start.main>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd9a8) at ../sysdeps/nptl/libc_start_call_main.h:74
#6  0x00007ffff7ceae25 in __libc_start_main_impl (main=0x113d560 <start.main>, argc=1, argv=0x7fffffffd9a8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd998)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions