OcctQtViewer Deletion Crash

Hello,

I encounter a crash when i try to delete OcctQtViewer. When OcctQtViewer destructor works, program crashes. I do not want OcctQtViewer live for the life cycle of the application. I need to open/close the page frequently. The same logic at https://github.com/gkv311/occt-samples-qopenglwidget applied.

Note: I do not do double deletion, opencascade handles memory management.

Do you have any idea about this error?
Thanks in advance.

Nezihe Sözen's picture

Hello @Kirill Gavrilov

We did some more experimentation on the subject and created a small test application to share the codes. The OcctQtViewer class is exactly the same as the example on github. As can be seen in the image, buttons that perform close, show and delete operations are attached to the OcctQtViewerwidget. During the close operation, the application does not crash, but when the destructor of the OcctQtViewer class is called in the delete operation, the application crashes after sending the SIGSEGV signal.

If we assign the instance we got from mainwindow to OcctQtViewer as its parent, this time we get a "Default FBO Wrapper Creation Failed" error in OcctQtViewer.

Is there any method you can suggest to solve this error?
Thank you.

Kirill Gavrilov's picture

The crash within QOpenGLWidget destructor is specific to Linux platform.

OcctQtViewer wraps OpenGL context created by QOpenGLWidget, but creates it's own X11 server connection within default Aspect_DisplayConnection constructor. When OCCT viewer is destroyed, OpenGL context and this X11 connection is not released with glXMakeCurrent(), because OCCT doesn't own it. I guess that when QOpenGLWidget destructor calls glXMakeCurrent() with another X11 connection, GLX tries to do something with previous connection, which is already destroyed at this step leading to some memory corruption.

As a workaround, OcctQtViewer destructor might explicitly release active GLX OpenGL context while X11 connection is alive. Alternatively, Aspect_DisplayConnection might be created as a wrapper (using non-default constructor taking Aspect_XDisplay*) over X11 connection created by Qt (as far as I understand, this could be retrieved only with help of QX11Info in case of Qt).

The first option is pushed to the branch test_delete.

Nezihe Sözen's picture

Hello,

Many thanks to you for your solution. Now, when the Occt widget is deleted, it does not crash and we were able to overcome the problem thanks to you.

When I can better explain our problem by sharing the code, I am adding a small application code again.

When we click on first the "Other Page", "Open Child Page", and then "Open OCCT Page" buttons respectively, our widget cannot create a view. Default FBO cannot initialize.

However, if we call QDialog(parent) in ChildPage.cpp, the OcctQtViewer widget works perfectly. The situation we do not would like here is that we do not would like to open a separate tab. We have to keep it under MainWindow and manage it.

Can you share with us if there is something we missed? Is the problem from Qt or am I making a mistake while managing Open Cascade headers? The application is not very fancy in terms of interface, but I hope I was able to explain our problem.

Thank you again your great efforts and precious solutions.

Kirill Gavrilov's picture

It might be simpler to move this discussion to GitHub - by opening an issue for each problem with sample there.