Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why does the application crash?

Why does the application crash?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 870 Views 2 Watching
  • 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.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by 8Observer8
    #1

    Hello,

    I cannot to publish a video here. You can see it on discord (01:15 long, without voice): https://discord.com/channels/457523061650882570/1247941120390991884 You can download my example there.

    My example crashed when I uncommeent QMatrix4x4 m_viewMatrix; here:

    opengl_widget.h

    #ifndef OPENGL_WIDGET_H
    #define OPENGL_WIDGET_H
    
    #include <QtGui/QMatrix4x4>
    #include <QtGui/QOpenGLFunctions>
    #include <QtOpenGL/QOpenGLBuffer>
    #include <QtOpenGL/QOpenGLShaderProgram>
    #include <QtOpenGL/QOpenGLTexture>
    #include <QtOpenGLWidgets/QOpenGLWidget>
    
    class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
    {
    public:
        OpenGLWidget(QWidget *parent = nullptr);
    
    private:
        void initializeGL() override;
        void resizeGL(int w, int h) override;
        void paintGL() override;
    
    private:
        QOpenGLShaderProgram m_program;
        QOpenGLBuffer m_vertPosBuffer;
        QOpenGLBuffer m_texCoordBuffer;
        int m_uSamplerLocation;
        int m_uMvpMatrixLocation;
        QMatrix4x4 m_mvpMatrix;
        QMatrix4x4 m_projMatrix;
        // QMatrix4x4 m_viewMatrix;
        // QMatrix4x4 m_modelMatrix;
        // QOpenGLTexture m_texture;
    
        const float m_worldWidth = 200.f;
        const float m_worldHeight = 200.f;
        float m_worldAspect = m_worldHeight / m_worldWidth;
        int m_viewportX;
        int m_viewportY;
        int m_viewportWidth;
        int m_viewportHeight;
    };
    
    #endif // OPENGL_WIDGET_H
    

    opengl_widget.cpp

    #include "opengl_widget.h"
    
    OpenGLWidget::OpenGLWidget(QWidget *parent)
        : QOpenGLWidget(parent)
    {
    }
    
    void OpenGLWidget::initializeGL()
    {
        initializeOpenGLFunctions();
    }
    
    void OpenGLWidget::resizeGL(int w, int h)
    {
    }
    
    void OpenGLWidget::paintGL()
    {
    }
    
    Pl45m4P 1 Reply Last reply
    0
    • 8Observer88 Offline
      8Observer88 Offline
      8Observer8
      wrote on last edited by 8Observer8
      #13

      But now the problem is gone. I don't understand why. I have attached my example here: https://discord.com/channels/457523061650882570/1247941120390991884/1247955899369132163

      image.png

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #2

        Nobody else can see your video. Try different versions of Qt. If all of them have the same issue, file a bug report with your example.

        1 Reply Last reply
        0
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #3

          When it "crashes" (with what "reason"?) what does the stack trace show?

          8Observer88 1 Reply Last reply
          0
          • 8Observer88 8Observer8

            Hello,

            I cannot to publish a video here. You can see it on discord (01:15 long, without voice): https://discord.com/channels/457523061650882570/1247941120390991884 You can download my example there.

            My example crashed when I uncommeent QMatrix4x4 m_viewMatrix; here:

            opengl_widget.h

            #ifndef OPENGL_WIDGET_H
            #define OPENGL_WIDGET_H
            
            #include <QtGui/QMatrix4x4>
            #include <QtGui/QOpenGLFunctions>
            #include <QtOpenGL/QOpenGLBuffer>
            #include <QtOpenGL/QOpenGLShaderProgram>
            #include <QtOpenGL/QOpenGLTexture>
            #include <QtOpenGLWidgets/QOpenGLWidget>
            
            class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
            {
            public:
                OpenGLWidget(QWidget *parent = nullptr);
            
            private:
                void initializeGL() override;
                void resizeGL(int w, int h) override;
                void paintGL() override;
            
            private:
                QOpenGLShaderProgram m_program;
                QOpenGLBuffer m_vertPosBuffer;
                QOpenGLBuffer m_texCoordBuffer;
                int m_uSamplerLocation;
                int m_uMvpMatrixLocation;
                QMatrix4x4 m_mvpMatrix;
                QMatrix4x4 m_projMatrix;
                // QMatrix4x4 m_viewMatrix;
                // QMatrix4x4 m_modelMatrix;
                // QOpenGLTexture m_texture;
            
                const float m_worldWidth = 200.f;
                const float m_worldHeight = 200.f;
                float m_worldAspect = m_worldHeight / m_worldWidth;
                int m_viewportX;
                int m_viewportY;
                int m_viewportWidth;
                int m_viewportHeight;
            };
            
            #endif // OPENGL_WIDGET_H
            

            opengl_widget.cpp

            #include "opengl_widget.h"
            
            OpenGLWidget::OpenGLWidget(QWidget *parent)
                : QOpenGLWidget(parent)
            {
            }
            
            void OpenGLWidget::initializeGL()
            {
                initializeOpenGLFunctions();
            }
            
            void OpenGLWidget::resizeGL(int w, int h)
            {
            }
            
            void OpenGLWidget::paintGL()
            {
            }
            
            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #4

            @8Observer8 said in Why does the application crash?:

            m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
            

            Maybe I'm wrong, but m_viewMatrix seems not initialized when reaching this line?!

            What should lookAt multiply when there are no value?

            • https://doc.qt.io/qt-6/qmatrix4x4.html#lookAt

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            JonBJ 1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @8Observer8 said in Why does the application crash?:

              m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
              

              Maybe I'm wrong, but m_viewMatrix seems not initialized when reaching this line?!

              What should lookAt multiply when there are no value?

              • https://doc.qt.io/qt-6/qmatrix4x4.html#lookAt
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #5

              @Pl45m4
              But the OP states

              My example crashed when I uncommeent QMatrix4x4 m_viewMatrix; here:

              So he is only commenting/uncommenting a variable, not any code which accesses it which he shows is all commented out?
              And I don't know why he shows a whole bunch of commented code which is commented so not used, but there you are.

              8Observer88 Pl45m4P 2 Replies Last reply
              0
              • JonBJ JonB

                When it "crashes" (with what "reason"?) what does the stack trace show?

                8Observer88 Offline
                8Observer88 Offline
                8Observer8
                wrote on last edited by 8Observer8
                #6

                @JonB said in Why does the application crash?:

                When it "crashes" (with what "reason"?) what does the stack trace show?
                When I uncommnet this line in my example above:

                QMatrix4x4 m_viewMatrix;
                

                @Pl45m4 said in Why does the application crash?:

                Maybe I'm wrong, but m_viewMatrix seems not initialized when reaching this line?!

                The program cannot reach this line because I comment everything inside of opengl_widget.cpp file:

                // m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
                
                JonBJ 1 Reply Last reply
                1
                • 8Observer88 8Observer8

                  @JonB said in Why does the application crash?:

                  When it "crashes" (with what "reason"?) what does the stack trace show?
                  When I uncommnet this line in my example above:

                  QMatrix4x4 m_viewMatrix;
                  

                  @Pl45m4 said in Why does the application crash?:

                  Maybe I'm wrong, but m_viewMatrix seems not initialized when reaching this line?!

                  The program cannot reach this line because I comment everything inside of opengl_widget.cpp file:

                  // m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0));
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #7

                  @8Observer8 said in Why does the application crash?:

                  When I uncommnet this line in my example above:

                  Yes, I got that, as you can see. And I asked:

                  When it "crashes" (with what "reason"?) what does the stack trace show?

                  So I was expecting two answers, corresponding to the two question marks.

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Pl45m4
                    But the OP states

                    My example crashed when I uncommeent QMatrix4x4 m_viewMatrix; here:

                    So he is only commenting/uncommenting a variable, not any code which accesses it which he shows is all commented out?
                    And I don't know why he shows a whole bunch of commented code which is commented so not used, but there you are.

                    8Observer88 Offline
                    8Observer88 Offline
                    8Observer8
                    wrote on last edited by
                    #8

                    @JonB said in Why does the application crash?:

                    So he is only commenting/uncommenting a variable

                    Yes, only this line: QMatrix4x4 m_viewMatrix;. If I comment this line QMatrix4x4 m_viewMatrix; my example works

                    JonBJ 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @Pl45m4
                      But the OP states

                      My example crashed when I uncommeent QMatrix4x4 m_viewMatrix; here:

                      So he is only commenting/uncommenting a variable, not any code which accesses it which he shows is all commented out?
                      And I don't know why he shows a whole bunch of commented code which is commented so not used, but there you are.

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #9

                      @JonB said in Why does the application crash?:

                      So he is only commenting/uncommenting a variable, not any code which accesses it which he shows is all commented out?

                      I thought one implies the other... :)
                      Because it's indeed very odd to receive a crash on

                      QMatrix4x4 m_viewMatrix;
                      

                      while one line above in the header those two

                      QMatrix4x4 m_mvpMatrix;
                      QMatrix4x4 m_projMatrix;
                      

                      seem to work?!

                      Edit:

                      @8Observer8 Delete everything in your build directory and configure/re-build your project? Does this help?


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      0
                      • 8Observer88 Offline
                        8Observer88 Offline
                        8Observer8
                        wrote on last edited by 8Observer8
                        #10

                        It is very strange. I did nothing but it works:

                        private:
                            QOpenGLShaderProgram m_program;
                            QOpenGLBuffer m_vertPosBuffer;
                            QOpenGLBuffer m_texCoordBuffer;
                            int m_uSamplerLocation;
                            int m_uMvpMatrixLocation;
                            QMatrix4x4 m_mvpMatrix;
                            QMatrix4x4 m_projMatrix;
                            QMatrix4x4 m_viewMatrix;
                            QMatrix4x4 m_modelMatrix;
                            // QOpenGLTexture m_texture;
                        

                        You can see in my video that I didn't work before.

                        1 Reply Last reply
                        1
                        • 8Observer88 8Observer8

                          @JonB said in Why does the application crash?:

                          So he is only commenting/uncommenting a variable

                          Yes, only this line: QMatrix4x4 m_viewMatrix;. If I comment this line QMatrix4x4 m_viewMatrix; my example works

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #11

                          @8Observer8
                          I suggest you:

                          • Remove every line which is commented out. It is very difficult when people post code and say that it does not crash, but will crash if you change something. Please just post code which crashes, and if you like tell us what to comment out which prevents it crashing, not the other way around.

                          • Remove every variable declaration which is not used in the crashing code. If that makes it work again, add in only those variables which are required to make it crash.

                          And then hopefully answer the earlier questions if you want help.

                          8Observer88 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @8Observer8
                            I suggest you:

                            • Remove every line which is commented out. It is very difficult when people post code and say that it does not crash, but will crash if you change something. Please just post code which crashes, and if you like tell us what to comment out which prevents it crashing, not the other way around.

                            • Remove every variable declaration which is not used in the crashing code. If that makes it work again, add in only those variables which are required to make it crash.

                            And then hopefully answer the earlier questions if you want help.

                            8Observer88 Offline
                            8Observer88 Offline
                            8Observer8
                            wrote on last edited by 8Observer8
                            #12

                            @JonB said in Why does the application crash?:

                            And then hopefully answer the earlier questions if you want help.

                            Yes, sorry! I fixed it in the first post. This code worked (with commented QMatrix4x4 m_viewMatrix;):

                            opengl_widget.h

                            #ifndef OPENGL_WIDGET_H
                            #define OPENGL_WIDGET_H
                            
                            #include <QtGui/QMatrix4x4>
                            #include <QtGui/QOpenGLFunctions>
                            #include <QtOpenGL/QOpenGLBuffer>
                            #include <QtOpenGL/QOpenGLShaderProgram>
                            #include <QtOpenGL/QOpenGLTexture>
                            #include <QtOpenGLWidgets/QOpenGLWidget>
                            
                            class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
                            {
                            public:
                                OpenGLWidget(QWidget *parent = nullptr);
                            
                            private:
                                void initializeGL() override;
                                void resizeGL(int w, int h) override;
                                void paintGL() override;
                            
                            private:
                                QOpenGLShaderProgram m_program;
                                QOpenGLBuffer m_vertPosBuffer;
                                QOpenGLBuffer m_texCoordBuffer;
                                int m_uSamplerLocation;
                                int m_uMvpMatrixLocation;
                                QMatrix4x4 m_mvpMatrix;
                                QMatrix4x4 m_projMatrix;
                                // QMatrix4x4 m_viewMatrix;
                                // QMatrix4x4 m_modelMatrix;
                                // QOpenGLTexture m_texture;
                            
                                const float m_worldWidth = 200.f;
                                const float m_worldHeight = 200.f;
                                float m_worldAspect = m_worldHeight / m_worldWidth;
                                int m_viewportX;
                                int m_viewportY;
                                int m_viewportWidth;
                                int m_viewportHeight;
                            };
                            
                            #endif // OPENGL_WIDGET_H
                            

                            opengl_widget.cpp

                            #include "opengl_widget.h"
                            
                            OpenGLWidget::OpenGLWidget(QWidget *parent)
                                : QOpenGLWidget(parent)
                            {
                            }
                            
                            void OpenGLWidget::initializeGL()
                            {
                                initializeOpenGLFunctions();
                            }
                            
                            void OpenGLWidget::resizeGL(int w, int h)
                            {
                            }
                            
                            void OpenGLWidget::paintGL()
                            {
                            }
                            

                            But this code crashed (I just uncommented QMatrix4x4 m_viewMatrix;)

                            opengl_widget.h

                            #ifndef OPENGL_WIDGET_H
                            #define OPENGL_WIDGET_H
                            
                            #include <QtGui/QMatrix4x4>
                            #include <QtGui/QOpenGLFunctions>
                            #include <QtOpenGL/QOpenGLBuffer>
                            #include <QtOpenGL/QOpenGLShaderProgram>
                            #include <QtOpenGL/QOpenGLTexture>
                            #include <QtOpenGLWidgets/QOpenGLWidget>
                            
                            class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
                            {
                            public:
                                OpenGLWidget(QWidget *parent = nullptr);
                            
                            private:
                                void initializeGL() override;
                                void resizeGL(int w, int h) override;
                                void paintGL() override;
                            
                            private:
                                QOpenGLShaderProgram m_program;
                                QOpenGLBuffer m_vertPosBuffer;
                                QOpenGLBuffer m_texCoordBuffer;
                                int m_uSamplerLocation;
                                int m_uMvpMatrixLocation;
                                QMatrix4x4 m_mvpMatrix;
                                QMatrix4x4 m_projMatrix;
                                QMatrix4x4 m_viewMatrix;
                                // QMatrix4x4 m_modelMatrix;
                                // QOpenGLTexture m_texture;
                            
                                const float m_worldWidth = 200.f;
                                const float m_worldHeight = 200.f;
                                float m_worldAspect = m_worldHeight / m_worldWidth;
                                int m_viewportX;
                                int m_viewportY;
                                int m_viewportWidth;
                                int m_viewportHeight;
                            };
                            
                            #endif // OPENGL_WIDGET_H
                            

                            opengl_widget.cpp

                            #include "opengl_widget.h"
                            
                            OpenGLWidget::OpenGLWidget(QWidget *parent)
                                : QOpenGLWidget(parent)
                            {
                            }
                            
                            void OpenGLWidget::initializeGL()
                            {
                                initializeOpenGLFunctions();
                            }
                            
                            void OpenGLWidget::resizeGL(int w, int h)
                            {
                            }
                            
                            void OpenGLWidget::paintGL()
                            {
                            }
                            
                            1 Reply Last reply
                            0
                            • 8Observer88 Offline
                              8Observer88 Offline
                              8Observer8
                              wrote on last edited by 8Observer8
                              #13

                              But now the problem is gone. I don't understand why. I have attached my example here: https://discord.com/channels/457523061650882570/1247941120390991884/1247955899369132163

                              image.png

                              1 Reply Last reply
                              0
                              • 8Observer88 8Observer8 has marked this topic as solved on
                              • JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #14

                                OK, but next time for

                                When it "crashes" (with what "reason"?) what does the stack trace show?

                                You should be given a notification of what caused the crash (e.g. SIGSEGV) and running it inside a debugger you should be able to find a stack trace for the crash. It helps if you look at/post these.

                                1 Reply Last reply
                                1

                                • Login

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