Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error message "create: CreateWindowEx failed"



  • Hello,

    I have a really simple code which looks like this :

    class myView : public QWidget {
      Q_OBJECT
    
    public:
      myView() {
        mView = new QGraphicsView();
        setWidget(mView);
        QGraphicsScene * scene = new QGraphicsScene();
        mView.setScene(scene);
      }
    
      void updateView() {
        QGraphicsScene * oldScene = mView->scene();
        QGraphicsScene * newScene = new QGraphicsScene();
        // I add different widgets and graphicsWidgets in the newScene depending on my model
        mView->setScene(newScene);
        oldScene->deleteLater();
      }
    private:
      QGraphicsView * mView = nullptr;
    }
    

    The idea is that I have different widgets and graphicsWidgets in the 'newScene'. I have connected user interaction with a signal which is received by an object containing the object myView. A computation is done to modify the model and my view is updated through 'updateView'. The processing chain is : clickOnWidget -> signal to model -> model update -> update view with 'updateView'.

    I works well many times but, after different calls to 'updateView', I get a segfault with the following message I do not understand :

    create: CreateWindowEx failed (Le processus actuel a utilisé tout son lot alloué par le système de descripteurs pour les objets du Gestionnaire de fenêtre.)
    
    Failed to create platform window for QWidgetWindow(0x1f031f60, name="QLabelClassWindow") with flags QFlags<Qt::WindowType>(Window|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint|WindowFullscreenButtonHint)
    

    Do you have any idea about what could be the source of this segfault ? Thanks in advance !


  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?
    On what version of Windows ?



  • Hello SGaist, I am on win 10 using QT 5.9.

    Note that I first tried to use oldScene->clear() before trying to swap between oldScene and newScene but I got same issue.


  • Lifetime Qt Champion

    Do you check with a more recent version of Qt ?



  • Unfortunately, I do not master the version of Qt I use. I can test it on a Linux (Ubuntu) platform tomorrow.

    Are you thinking about a known/fixed bug ?



  • If instead of

    ...   
        mView->setScene(newScene);
        oldScene->deleteLater();
    }
    ...
    

    you try

    ...
        mView->setScene(newScene);
        delete oldScene;
    }
    ...
    

    does it still crash?



  • @Julieng
    I am interested: why do you create a newly allocated scene and delete the current one, why not just clear out the current one and add your new stuff into it? I am a graphics beginner.



  • I have tried 3 differents approaches (because I really do not understand the error message) :

    • first: use a single scene with clear() function (I think it is @JonB solution). It crashed so I though it was related to a possible late call to a cleared object
    • second, I tried @hskoglund solution using 'delete'. Since I got same crash, I tried a third option
    • third: use a deleteLater

    If it helps, the probability to crash is far higher when there is a large number of items in the scene (quite no crash with around 100 items but regular crash with about 1000 items)



  • @Julieng
    Sounds like the deleteLater reduces the frequency of the problem but still is not right. I think I'd worry first about why clear() and re-use does not work. But then I did say I'm a beginner, so I don't know!



  • I just tried it on Linux (Ubuntu 19.10) and I have no issue.



  • Tested today with a Qt 5.12 on Windows and I still have the issue. Any ideas about how to avoid this issue ? Thanks.



  • Well, firstly you'll never get a CreateWindowEx error under Linux because that is the name of a native Windows(-only) function for creating a window!

    create: CreateWindowEx failed (Le processus actuel a utilisé tout son lot alloué par le système de descripteurs pour les objets du Gestionnaire de fenêtre.)

    This almost certainly means that you have exceeded the number of "Window Manager objects" allowed, Windows has run out of handles. That will be why it "works well many times", till the maximum gets exceeded.

    As we have said before, the "best guess" would be that you are failing to delete/leaking window handles somewhere.

    Under Windows there are external tools (you'll have to Google) for examining what windows/objects/handles are in use by Windows. You might that useful.



  • Interesting comment @JonB. I do not create any new window in this process but I have sub-classed QDockWidget to carry my view (called "myView" in my exemple). Here is the code (to avoid closing a QDockWidget with ALT+F4):

    #include "uncloseableDockWidget.h"
    #include <QCloseEvent>
    
    uncloseableDockWidget::uncloseableDockWidget(const QString & title, QWidget * parent, Qt::WindowFlags flags) : QDockWidget(title, parent, flags) {
        setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
        setAllowedAreas(Qt::AllDockWidgetAreas);
    }
    
    uncloseableDockWidget::~uncloseableDockWidget() {
    }
    
    void uncloseableDockWidget::closeEvent(QCloseEvent * event) {
        event->ignore();
    }
    

    Could the closeEvent interact with something in my view. I do not see direct link but as you explain that I could have not deleted something, it rings my bell !



  • @Julieng
    It doesn't shout at me. Remove to test?

    The idea is that I have different widgets and graphicsWidgets in the 'newScene'.

    Every QWidget you create will have a Windows window CreateWindowEx. I don't know about your "graphicsWidgets ". I'm thinking you are creating a "large" number of these. That would happen if you're are not destroying them, for whatever reason. I'm thinking the error message is pretty severe!

    create: CreateWindowEx failed (Le processus actuel a utilisé tout son lot alloué par le système de descripteurs pour les objets du Gestionnaire de fenêtre.)

    Google to find the correct corresponding English error message. Then Google for that. Find out why it would be issued. There must be tool to show how many windows have been created by a process or in the system as a whole, and see if that is indeed "large". Look for you using up all of them!


  • Lifetime Qt Champion

    Hi,

    The error states that you exhausted all the available descriptors for objects of the window manager. Any chances you are leaking widgets or other graphical components ?



  • @Julieng
    @SGaist has confirmed what I suggested --- you must surely(?) be leaking widgets somewhere in your code, causing Windows to run out of windows(!). The fact that you reported clear() crashed, and delete crashed, and deleteLater() crashed after a while must be indicating something is awry.

    For widgets only (unfortunately), for debugging "orphanages" I use https://doc.qt.io/qt-5/qapplication.html#allWidgets. You can walk that to see what's in existence, or has no parent. Even if all you do is examine its length at an appropriate point in your code, if there are a "large number" there when there shouldn't be it shows you have some leak....

    For QObject-derived classes (including QWidget) you can slot onto the https://doc.qt.io/qt-5/qobject.html#destroyed signal. If you simply count there, if you create 1,000 QObjects but don't see that many destroyed, you're leaking.

    For your QGraphicsItems unfortunately neither of these techniques apply. I'm not sure if they can ever get orphaned from a QGraphicsScene. Though creating a QGraphicsItem(nullptr) and then failing to call QGraphicsScene::addItem() would leave it dangling, as would calling QGraphicsScene::removeItem() and then not deleting it yourself afterward. Some food for thought.



  • @SGaist and @JonB , thanks a lot for your help ! I have used 'QApplication::allWidgets().size()' to track where I am leaking and indeed, I was generating lots of widgets from call to call. That's solved.



  • @Julieng
    Yay! QApplication::allWidgets() is my favorite QWidgets function :) I have a debugging function which walks them via parent, reporting on all those which are top-level orphaned even if they compose a tree.


Log in to reply