coin3d / quarter

Coin GUI binding for Qt
BSD 3-Clause "New" or "Revised" License
39 stars 28 forks source link

Segmentation fault when running the minimal.cpp example #55

Closed xiaodaxia-2008 closed 8 months ago

xiaodaxia-2008 commented 2 years ago

I got the following error when running a basic minimal.cpp.

Thread 1 "Example" received signal SIGSEGV, Segmentation fault.
0x00007ffff6ae5d72 in QOpenGLContext::makeCurrent(QSurface*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
(gdb) bt
#0  0x00007ffff6ae5d72 in QOpenGLContext::makeCurrent(QSurface*) () at /lib/x86_64-linux-gnu/libQt5Gui.so.5
#1  0x00007ffff769bb49 in QGLContext::makeCurrent() () at /lib/x86_64-linux-gnu/libQt5OpenGL.so.5
#2  0x00007ffff76a1a21 in QGLWidgetPrivate::makeCurrent() () at /lib/x86_64-linux-gnu/libQt5OpenGL.so.5
#3  0x00007ffff7fbfb88 in SIM::Coin3D::Quarter::QuarterWidgetP::removeFromCacheContext(QuarterWidgetP_cachecontext*, QGLWidget const*) () at /home/rvbust/Rvbust/Sources/quarter/Build/lib/libQuarter.so.20
#4  0x00007ffff7fbfc20 in SIM::Coin3D::Quarter::QuarterWidgetP::~QuarterWidgetP() ()
    at /home/rvbust/Rvbust/Sources/quarter/Build/lib/libQuarter.so.20
#5  0x00007ffff7fbe738 in SIM::Coin3D::Quarter::QuarterWidget::~QuarterWidget() ()
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/rvbust/Rvbust/Sources/quarter/Build/lib/libQuarter.so.20
#6  0x00007ffff7fbe769 in SIM::Coin3D::Quarter::QuarterWidget::~QuarterWidget() ()
    at /home/rvbust/Rvbust/Sources/quarter/Build/lib/libQuarter.so.20
#7  0x0000000000401381 in main ()

the source code of minimal.cpp is

#include <Inventor/nodes/SoCone.h>
#include <Inventor/nodes/SoBaseColor.h>
#include <Inventor/nodes/SoSeparator.h>

#include <Quarter/Quarter.h>
#include <Quarter/QuarterWidget.h>

#include <QApplication>
#include <QMainWindow>
#include <memory>

using namespace SIM::Coin3D::Quarter;

int
main(int argc, char ** argv)
{
  // Initializes Quarter (and implicitly also Coin and Qt
  QApplication app(argc, argv);
  Quarter::init();

  // Make a dead simple scene graph by using the Coin library, only
  // containing a single yellow cone under the scenegraph root.
  SoSeparator * root = new SoSeparator;
  root->ref();

  SoBaseColor * col = new SoBaseColor;
  col->rgb = SbColor(1, 1, 0);
  root->addChild(col);

  root->addChild(new SoCone);

  QMainWindow * mainwin = new QMainWindow();

  // Create a QuarterWidget for displaying a Coin scene graph
  QuarterWidget * viewer = new QuarterWidget(mainwin);
  //set default navigation mode file
  viewer->setNavigationModeFile();
  mainwin->setCentralWidget(viewer);
  viewer->setSceneGraph(root);

  // Pop up the QuarterWidget
  mainwin->show();
  // Loop until exit.
  app.exec();
  // Clean up resources.
  delete viewer;
  root->unref();
  delete mainwin;

  Quarter::clean();

  return 0;
}

Could anyone know something about how to fix it? Thanks very much.

ggabbiani commented 2 years ago

Seems similar to issue #10 , a test could be removing the workaround for a Coin issue fixed in svn r12818 in the QuarterWidgetP::removeFromCacheContext() method.

Regards Giampiero

xiaodaxia-2008 commented 2 years ago

sorry, but I'm still confused about how to fix it? Is the suggestion in #10 to comment the removeFromCacheContext() in the destructor ?

ggabbiani commented 2 years ago

It is passed really a lot of time from when I opened the issue, and at present I don't have any mercurial repo from which reconstruct my conclusions about.

Giving a look to the source I think to remember that the mercurial commit 30d08ea consisted solely of line 195 on QuarterWidgetP.cpp.

// fetch the cc_glglue context instance as a workaround for a bug fixed in Coin r12818
(void) cc_glglue_instance(context->id);

You can try to comment it and try it out but - as already mentioned at the time - it was - and still is - not clear to me why this commit introduced the regression.

Regards Giampiero

VolkerEnderlein commented 2 years ago

Looks like this issue started to occur when using Qt5, as I checked with Qt 4.8.7 and everything was fine. I debugged the application and found out that the QGLContext of the QuarterWidget is reset when the call to QApplication exec() returns. Then in the QuarterWidgetP destructor the calls widget->makeCurrent() and widget->doneCurrent() crash as there is a null pointer dereference inside. Will provide a fix soon.