Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML+Qt: Crash when deleting/closing a QWidget that is also a sf::RenderWindow  (Read 7563 times)

0 Members and 1 Guest are viewing this topic.

glc

  • Newbie
  • *
  • Posts: 2
    • View Profile
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
« Last Edit: July 29, 2021, 01:44:07 pm by glc »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

glc

  • Newbie
  • *
  • Posts: 2
    • View Profile
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!