您当前的位置: 首页 >  3d
  • 0浏览

    0关注

    483博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

3D进阶之OSG: Qt程序退出时在QScopedPointer中崩溃

高精度计算机视觉 发布时间:2022-04-07 22:57:13 ,浏览量:0

今天调试一个osgQt的应用程序,在程序退出时发生崩溃。使用的是Qt5.15.0。

查了一下,原因在这里,

[QTBUG-93173] QGLContext::makeCurrent() crashes due to d->guiGlContext being null - Qt Bug Tracker

最新版本应该已经修复了这个问题。

原因:

在程序运行过程中,主程序会不断轮询所有的widget的,并传递消息。但在退出时,glcontext其实已经在析构,此时碰到没有nullptr检查,再次把widget设置为当前用例时,就会崩溃。

解决办法:

原作者是这么说的:

At the application level the following check can be made:

auto *_context = context()->contextHandle();
if (nullptr == _context || !_context->isValid())
{
  return ;
}

问题是:我们要怎么改?

接上一篇文章:3D进阶之OSG:编译osgQt的旧版本_高精度计算机视觉的博客-CSDN博客

老版本的osgQt源码在这里:https://github.com/mathieu/osgQt 

找到函数


bool GraphicsWindowQt::makeCurrentImplementation()
{
    if (_widget->getNumDeferredEvents() > 0)
        _widget->processDeferredEvents();

    _widget->makeCurrent();    

    return true;
}

修改后的源码如下,

bool GraphicsWindowQt::makeCurrentImplementation()
{
    if (_widget->getNumDeferredEvents() > 0)
        _widget->processDeferredEvents();

    /*
    https://bugreports.qt.io/browse/QTBUG-93173
    auto* _context = _widget->context()->contextHandle();
    if (nullptr == _context || !_context->isValid()){
        return;
    }
    */
    QOpenGLContext* _context = _widget->context()->contextHandle();
    if (nullptr == _context || !_context->isValid())
    {
        return false;
    }

    _widget->makeCurrent();    

    return true;
}

最后,更新修改后的源码在这里,

GitHub - SpaceView/osgQtOld: Updated old version of osgQt from https://github.com/mathieu/osgQt

本文结束

关注
打赏
1661664439
查看更多评论
立即登录/注册

微信扫码登录

0.0595s