DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

destroy_context doesn't clean up the window

Open PhilippThoelke opened this issue 9 months ago • 13 comments

Version of Dear PyGui

Version: 1.9.1 Operating System: Ubuntu 22.04 (KDE Plasma 5.27.7)

My Issue

Calling dpg.destroy_context() doesn't close the window, but just makes it unresponsive. This seems like a very basic thing, so maybe there's something wrong with my OS or window manager? It works as expected on my Windows 11 system. I also tried a range of DPG versions, all of them have the same issue on my Linux system.

To Reproduce

Run the code below and simply close the window by clicking on the x. The window doesn't close but just becomes unresponsive. It does unblock dpg.start_dearpygui(), calls destroy_context and goes into the while True loop as expected.

image

Expected behavior

The window should close properly.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

with dpg.window(label="tutorial"):
    dpg.add_text("Hello world")

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

print("window closed")

while True:
    pass

PhilippThoelke avatar Sep 10 '23 19:09 PhilippThoelke

Probably Linux-only (with the minimal example given), because on Windows you can only get to print("window closed") by closing the window :rofl:

v-ein avatar Sep 10 '23 20:09 v-ein

Here's a modified example that will show somewhat similar behavior on Windows:

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

with dpg.window(label="tutorial"):
    dpg.add_text("Hello world")
    dpg.add_button(label="Exit", callback=lambda: dpg.stop_dearpygui())

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

print("window closed")

while True:
    pass

Instead of closing the window, press Exit - and you'll get an unresponsive window.

v-ein avatar Sep 10 '23 20:09 v-ein

Also, this is most probably a duplicate of #2013 - see my comment in that issue.

v-ein avatar Sep 10 '23 20:09 v-ein

Also, there's a discussion in #1593 which shows how old the issue is! :joy:

v-ein avatar Sep 10 '23 20:09 v-ein

Ah, sorry for the duplicate, moving to #2013.

PhilippThoelke avatar Sep 10 '23 21:09 PhilippThoelke

I'd like to point out that both #2013 and #1593 are closed - but not fixed. Let's leave at least one issue open ;)

v-ein avatar Sep 10 '23 21:09 v-ein

Alright, since I can't reopen the other issues I'll stay here :D

Any plans on addressing this issue? If you are sure that mvCleanupViewport provides the intended functionality I could look into adding it to destroy_context(), if you think that makes sense.

PhilippThoelke avatar Sep 10 '23 21:09 PhilippThoelke

I'm not sure how to fix this issue properly - it's up to @hoffstadt to decide... It might well be that mvCleanupViewport needs some rework. Unfortunately I don't have spare time at the moment to play with mvCleanupViewport. Maybe later.

v-ein avatar Sep 10 '23 21:09 v-ein

Having the same issue on POPOS with SwayWM. I have to kill the python process to close the viewport. Is there a way around this? For now this is a showstopper for me to use dpg!

artelse avatar Nov 13 '23 23:11 artelse

On Windows, you could use WinAPI wrappers to close your window directly. I don't know if such a package exists on Linux - basically you need some kind of a SwayWM or Wayland API. Google says there's PyWayland, at least.

This would make your code platform-dependent, but with this kind of issues there's no cross-platform workarounds.

v-ein avatar Nov 14 '23 06:11 v-ein

Other GUI frameworks I tried don't have this problem and am unsure if this is wayland related, more seems like a bug or oversight.

artelse avatar Nov 14 '23 12:11 artelse

It's a bug in DPG, just like I said in a comment in another ticket.

I'm talking about Wayland because you can use its API to forcefully close the window - as a workaround for the DPG bug. DPG does not close the window itself. Most users don't see it because their programs end immediately after dpg.destroy_context().

v-ein avatar Nov 14 '23 13:11 v-ein

As an option, use dpg.minimize_viewport before destroy_context to get the unresponsive window out of view. Only if your program ends in a reasonably short time after that (so that the user doesn't try to restore the minimized window).

v-ein avatar Nov 14 '23 13:11 v-ein