SFML community forums

Help => Window => Topic started by: glc on July 29, 2021, 01:35:47 pm

Title: SFML+Qt: Crash when deleting/closing a QWidget that is also a sf::RenderWindow
Post by: glc on July 29, 2021, 01:35:47 pm
Hello!
While integrating SFML (2.5.1) with Qt (5.15.2) in macOS I found that I can't delete an object that inherits from both QWidget and sf::RenderWindow because it crashes. The message the debug console shows before crashing is:

Cannot close SFML area when SFML is integrated in a NSView.
Cannot close SFML area when SFML is integrated in a NSView.
2021-07-29 13:18:42.123407+0200 sfmlqt[79650:1336970] Premature drain of QMacAutoReleasePool(0x7ffee7eab8a8) This can happen if you've allocated the pool on the heap, or as a member of a heap-allocated object. This is not a supported use of QMacAutoReleasePool, and might result in crashes when objects in the pool are deallocated and then used later on under the assumption they will be valid until QMacAutoReleasePool(0x7ffee7eab8a8) has been drained.


I've made a minimal example (see code files attached) in order to reproduce the crash. It is a program with two widgets, the one that inherits from QWidget and sf::RenderWindow (called WindowWidget) and a button that destroys the WindowWidget when it is clicked.

In Windows it works fine.

Am I missing something? Is there a reason I can't delete that object? Is there any workaround?

Thanks in advance
Title: Re: SFML+Qt: Crash when deleting/closing a QWidget that is also a sf::RenderWindow
Post by: eXpl0it3r on August 05, 2021, 12:22:56 pm
You'd have to follow the objective-C calls on those NSViews to see where they end up being "locked".
From a design point of view, I probably wouldn't derive your widget class from sf::RenderWindow as you don't really want all the functions of the window externally exposed, but instead want the widget to deal with proper resizing and lifetime management.
Title: Re: SFML+Qt: Crash when deleting/closing a QWidget that is also a sf::RenderWindow
Post by: glc on August 24, 2021, 11:10:12 am
Hello,
I've just followed the example as in the tutorial (https://www.sfml-dev.org/tutorials/1.6/graphics-qt.php), but if that is not correct it would be great to mark it as incorrect or just delete the page. I don't see how should it be done if not deriving from sf::RenderWindow.

The way we solved it is by rebuilding the SFML with all the methods from AutoreleasePoolWrapper.mm commented so the memory management is done only by Qt.

It seems to be the same issue as reported in https://github.com/SFML/SFML/issues/1549

Thanks!