Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120964

delayed creation of QAttribute with parent in constructor causes crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.6.2, 6.7.0 Beta2, 6.8.0 FF
    • 6.6.1
    • Qt3D
    • None
    • Windows
    • 0d4a4a9ef (dev), 14264f82e (6.7), 6907e014f (6.6)

    Description

      After event loop started, if you give non-null parent when creating QAttribute, the application crashes.

      Here's example code:

      #include <QtGui>
      #include <Qt3DCore>
      #include <Qt3DRender>
      #include <Qt3DExtras>
      
      using namespace Qt3DCore;
      using namespace Qt3DRender;
      using namespace Qt3DExtras;
      
      auto test(QEntity *parent) -> QEntity*
      {
          auto entity = new QEntity{parent};
          auto material = new QDiffuseSpecularMaterial;
          entity->addComponent(material);
      
          QVector3D pos[] = {{0, 0, 5}, {1, 0, 5}, {0, 1, 5}};
          auto buffer = new Qt3DCore::QBuffer;
          buffer->setData(QByteArray(reinterpret_cast<const char*>(pos), sizeof(pos)));
      #define ERROR_CASE
      #ifdef ERROR_CASE
          auto positions = new QAttribute(entity);
      #else
          auto positions = new QAttribute;
          positions->setParent(entity);
      #endif
          positions->setBuffer(buffer);
          positions->setName(QAttribute::defaultPositionAttributeName());
          positions->setVertexBaseType(QAttribute::Float);
          positions->setVertexSize(3);
          positions->setCount(3);
      
          auto geometry = new QGeometry;
          geometry->addAttribute(positions);
          auto view = new QGeometryView;
          view->setGeometry(geometry);
          view->setPrimitiveType(QGeometryView::Triangles);
      
          auto renderer = new QGeometryRenderer;
          renderer->setView(view);
          entity->addComponent(renderer);
      
          return entity;
      }
      
      int main(int argc, char *argv[])
      {
          qputenv("QT3D_RENDERER", "opengl");
          qputenv("QSG_RHI_BACKEND", "opengl");
      
          QGuiApplication a(argc, argv);
      
          Qt3DWindow view;
      
          auto camera = view.camera();
          camera->setPosition(QVector3D(0, 0, 10));
          camera->setViewCenter(QVector3D(0, 0, 0));
      
          auto root = new QEntity;
          QTimer::singleShot(0, [&] { test(root); });
          view.setRootEntity(root);
          view.show();
      
          return a.exec();
      }
      

      If you comment out `#define ERROR_CASE` to create QAttribute without parent, it works without crash even though calling QAttribute::setParent() right after creation.
      It also works too if you call test() before app.exec() instead of delaying using QTimer::singleShot().

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            seanharmer Sean Harmer
            bylee Byoung-young Lee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes