githubuser0xFFFF / Qt-Advanced-Docking-System

Advanced Docking System for Qt
GNU Lesser General Public License v2.1
1.87k stars 548 forks source link

Corruption of event queue in case of deleteDockWidget + restoreState #644

Closed alexisperin closed 3 months ago

alexisperin commented 4 months ago

Hello,

I came across a nasty bug using the library. What happened is I called deleteDockWidget on a floating CDockWidget (which calls a deleteLater in your implementation) and right after that I called restoreState on the CDockManager to load an other configuration that also contains a floating CDockWidget. The restoreState method is called before the deleteLater but once the deleteLater is executed my application crashes.

I guess what happens is restoreState tries to re-use the CDockContainer of the floating widget I was trying to delete and that container is then deleted too once the deleteLater is executed on the floating widget.

There is no doubt that this kind bug was unpredictable. But I would be very gratefull if you could take a look at was is possible to do to add some more security in the code and prevent such a crash.

Thanks,

Alexis

githubuser0xFFFF commented 4 months ago

Will it help, if you call QApplication::processEvents() right before you call restoreState()?

alexisperin commented 4 months ago

Thank you for your answer. Calling processEvents() doesn't solve my problem, it looks like DeferredDelete events are handled differently than others (https://doc.qt.io/qt-6/qcoreapplication.html#processEvents).

The fix I currently have is to queue the call to restoreState(). This makes sure it is executed after the deleteLater. I am just wondering if there is something you could do on your side to avoid such a workaround ?

githubuser0xFFFF commented 3 months ago

At the moment you are the only one with this issue so please use your work around.