Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QOpenGLContext memory leak

QOpenGLContext memory leak

Scheduled Pinned Locked Moved Solved Game Development
5 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by Megamouse
    #1

    Hi everyone,

    I've got this problem where deleting my OpenGLContext does not work. The VRAM increases with every new creation of MyWindow. The context is created in another Thread with following code.

    if (void* context = MakeContext())
    {
    	return std::shared_ptr<void>(context, [this](void* cxt) { DeleteContext(cxt); });
    }
    
    void* MyWindow::MakeContext()
    {
    	auto context = new QOpenGLContext();
    	context->setFormat(m_format);
    	context->create();
    	return context;
    }
    
    void MyWindow::DeleteContext(void* context)
    {
    	((QOpenGLContext*)context)->deleteLater();
    }
    

    Using following method results in a random crash on new Creation of MyWindow after the first time.
    Yet it fixes the VRAM issue.

    void MyWindow::DeleteContext(void* context)
    {
    	delete (QOpenGLContext*)context;
    }
    

    What am I doing wrong?

    Edit:
    I noticed it crashes on new context creation.

    void* MyWindow::MakeContext()
    {
    	auto context = new QOpenGLContext();
    	context->setFormat(m_format);
    	context->create(); // this line crashes
    	return context;
    }
    
    1 Reply Last reply
    0
    • MegamouseM Offline
      MegamouseM Offline
      Megamouse
      wrote on last edited by
      #2

      Somehow this seems to have fixed it to some extend. But I have no clue why and if it is the best solution.

      void MyWindow::DeleteContext(void* context)
      {
      	QOpenGLContext* trash = ((QOpenGLContext*)context);
      	trash->deleteLater();
      	trash->~QOpenGLContext();
      }
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You should use qobject_cast rather that C style cast. Then calling the destructor is usually not something you do. You should simply replace deleteLater for delete if you want to delete everything immediately.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • MegamouseM Offline
          MegamouseM Offline
          Megamouse
          wrote on last edited by
          #4

          It would not have made a difference. It was a bug in the AMD driver. Our expert used native routines and it still crashed

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Thanks for the feedback !

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved