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
172 stars 25 forks source link

Access violation fix #44

Closed hannesdelbeke closed 1 year ago

hannesdelbeke commented 1 year ago

this PR addresses an issue with access violation mentioned in PR https://github.com/techartorg/bqt/pull/42 there is also some logic cleanup, since some funtions are called multiple times or in wrong places.

details:

QApplication is instanced, and a reference is saved in a variable in the QOperator. the blender window is wrapped in QT, and is now managed by pyside/ the QApplication

when closing blender, operators likely get deregistered, which means the reference to QApplication is gone, and QApplication gets garbage collected. but blender is managed by the QApp, which tries to delete all it's widgets etc.

since the operator owns qapp, qapp owns blender, and blender owns the operator. we have a loop.

moving the qapp to a global variable instead of the operator seems to fix the access violation error :D

notes the specific commit that fixes the violation is the removal of the qoperator. replacing it with just a function

hannesdelbeke commented 1 year ago

approved by Frieder in slack

hannesdelbeke commented 1 year ago

hmm on further testing this has an issue. it works all nicely, no exception on closing.

but if you launch a qt window, you get a different error on closing now Error: Not freed memory blocks: 4, total unfreed memory 0.000351 MB