techartorg / bqt

A Blender add-on to support & manage Qt Widgets in Blender (PySide2)
https://github.com/techartorg/bqt/wiki
Mozilla Public License 2.0
162 stars 23 forks source link

Not freed memory blocks on blender close #47

Open hannesdelbeke opened 1 year ago

hannesdelbeke commented 1 year ago

after mergin in PR https://github.com/techartorg/bqt/pull/44 to fix the access violation exception, the following error happens on quiting blender, but only if a qt window was launched in blender Error: Not freed memory blocks: 4, total unfreed memory 0.000351 MB

Originally posted by @hannesdelbeke in https://github.com/techartorg/bqt/issues/44#issuecomment-1272013942

hannesdelbeke commented 1 year ago

this only happens if the qt window was parented to the blender_widget in qapp. no generic repro yet for mem not freed error

a default qdialog however doesn't do this when run in the blender terminal: e.g. closing blender after running the following doesn't cause the error.

import PySide2
import PySide2.QtWidgets
import PySide2.QtWidgets as w
d = w.QDialog()
d.show()
hannesdelbeke commented 1 year ago

closing blender after running the following cause an acces violation exception this is a different issue, but likely related

import PySide2
import PySide2.QtWidgets
import PySide2.QtWidgets as w

from PySide2.QtWidgets import QApplication
app = QApplication.instance()
bw = app.blender_widget

#d = w.QDialog() # this is fine
d = w.QDialog(bw) # acces violation on exit
d.show()
# close blender now without closing the widget
ewerybody commented 1 year ago

We had something like

Error   : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FFA973DC23C
Module  : python310.dll
Thread  : 000053cc

on blender close with PySide2 5.15.2.1. I now just tried it all with PySide6. Works! 🚀

hannesdelbeke commented 1 year ago

Great to hear pyside6 fixed this ☺️

AFAIK this exception with pyside 2 doesnt cause issues since it only happens on closing blender, after executing any scripts hooked to exit.

Qt does mention any wrapping of a non qt window in a qt window is possible but not officially supported. So bugs like these are possible

hannesdelbeke commented 1 year ago

this bug prevented qt from saving the window position and size to restore in the next session. window code was changed to work around this https://github.com/techartorg/bqt/pull/76

hannesdelbeke commented 1 year ago

weirdly enough this still happens when bqt is set to no wrap mode, investigate. ... this might be good news, meaning the issue is not related to some of the window wrapping

hannesdelbeke commented 1 year ago

We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function. This is because, on some platforms the QApplication::exec() call may not return. For example, on the Windows platform, when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function, after the QApplication::exec() call.

source