hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.89k stars 671 forks source link

Cannot save ini file on exit, dearpygui already exited #1448

Closed west-rynes closed 2 years ago

west-rynes commented 2 years ago

Version of Dear PyGui

DPG Version: 1.1.1 OS: macOS-10.15.7-x86_64-i386-64bit

My Issue/Question

Would be nice to be able to save the ini files using the exit callback. But it seems everything has exited. Seems like the utility of set_exit_callback is currently broken.

I think this is related to #1390

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg
import dearpygui

import platform
print(f"DPG Version: {dearpygui.__version__}")
print(f"OS: {platform.platform()}")

dpg.create_context()

dpg.configure_app(
    wait_for_input=False, # Can set to true but items may not live update. Lowers CPU usage
    init_file="temp.ini",
    docking=True,
    docking_space=True
    ) 

def exit_callback():
    print("Exit called...")
    dpg.save_init_file("temp.ini")

with dpg.window() as main_window:
    dpg.add_text("Hello")

dpg.create_viewport()
dpg.setup_dearpygui()
dpg.set_primary_window(main_window, True)
dpg.show_viewport()
dpg.set_exit_callback(exit_callback)
dpg.start_dearpygui()
dpg.destroy_context()

Output

Exit called...
Exception: Error: [1000] Message:       Dear PyGui must be started to use "save_init_file".

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/atanbak/dev/MONOREPO/experimental/libs/dearpygui-eval/bugs/exit_callback.py", line 19, in exit_callback
    dpg.save_init_file("temp.ini")
  File "/Users/atanbak/Library/Caches/pypoetry/virtualenvs/msi-IwjgdkSm-py3.9/lib/python3.9/site-packages/dearpygui/dearpygui.py", line 8614, in save_init_file
    return internal_dpg.save_init_file(file, **kwargs)
SystemError: <built-in function save_init_file> returned a result with an error set
Mstpyt commented 2 years ago

As a Workaround till it is fixed:

import dearpygui.dearpygui as dpg
import dearpygui

import platform

print(f"DPG Version: {dearpygui.__version__}")
print(f"OS: {platform.platform()}")

dpg.create_context()

dpg.configure_app(
    wait_for_input=False,  # Can set to true but items may not live update. Lowers CPU usage
    init_file="temp.ini",
    docking=True,
    docking_space=True
)

def exit_callback():
    print("Exit called...")
    dpg.save_init_file("temp.ini")

with dpg.window(on_close=lambda sender, data: exit_callback) as main_window:
    dpg.add_text("Hello")

dpg.create_viewport()
dpg.setup_dearpygui()
dpg.set_primary_window(main_window, True)
dpg.show_viewport()
#dpg.set_exit_callback(exit_callback)
dpg.start_dearpygui()
dpg.destroy_context()
hoffstadt commented 2 years ago

Fixed in next release.

RyanQ96 commented 6 months ago

Still has segmentation fault: DPG Version: 1.10.0