-
-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resize handlers might be running while DPG context is being destroyed #2020
Comments
Looks like it does crash the application on exit from time to time. Depends on what's in the resize handler - mine got a bit more complex, and started giving me segfaults. |
Looks like this applies to all other handlers, too, though it would be more difficult to recreate for other handlers. The basic problem is that events are born in the renderer thread but are handled in the handlers thread. Between these two moments, they "live" in a queue for a while. If the renderer thread starts manipulating the widget tree, like it does in Another, more complicated example of this issue would look like this:
It's difficult, if not impossible, to guard against such issues on the DPG side of things. Looks like it's what the user's program should do: if there's a chance your widget gets deleted, you know about this and must do an appropriate check (or catch exceptions). Nonetheless, there's a bug in DPG that causes a crash. The scenario above, on its own, does not lead to a hard crash, it can only give a mere exception in Python. Looks like the crash is caused by In this ticket, I think we should be focusing on the crash, and leaving existence checks to DPG users to do. Also: my suggestion that |
Does this still cause you issues? I tried to replicate it many times on my Ubuntu 24.04 but it always worked fine. if (GContext->viewport != nullptr)
mvCleanupViewport(*GContext->viewport); that maybe helped in this. |
Same thing with #2275:
Which is somewhat expected since |
Version of Dear PyGui
Version: 1.8.0
Operating System: Windows 10
My Issue/Question
When application's main window is closed,
dpg.destroy_context()
is typically called right away in order to shut down DPG. Looks like it does not wait until all handlers complete; in particular, if there was a dpg.window with a "resize" handler and autosize=True, there's a good chance that the handler runs in parallel withdestroy_context()
, and might eventually reference a DPG item that has already been destroyed bydestroy_context()
. This does not crash the application "natively" (with an access violation or something), but it does throw an exception like this:For some reason, the resize handler is called during termination when
autosize
is True, but not called forautosize=False
. Might be caused by DPG destroying the window's children and therefore causing it to auto-resize to a smaller size.One could explicitly remove all such handlers before shutting down DPG (i.e. in between
start_dearpygui()
anddestroy_context()
), but in a real-world application this would be a rather clumsy workaround.To Reproduce
Steps to reproduce the behavior:
Expected behavior
destroy_context()
should wait for the handlers thread to complete. (Disclaimer: I haven't looked at its code yet.)As an alternative, DPG could disable the resize handlers on a container if it's going to destroy it; this would be more of a workaround but seems to be a reasonable one.
I'm not sure which of the two ways would amount to less work. The former seems to be more robust since it also fixes other similar issues.
Screenshots/Video
I'm not providing a screenshot - you can find the error message above, and there's nothing to show in the GUI.
Standalone, minimal, complete and verifiable example
The text was updated successfully, but these errors were encountered: