Why does the application crash?
-
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_Hopengl_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 now the problem is gone. I don't understand why. I have attached my example here: https://discord.com/channels/457523061650882570/1247941120390991884/1247955899369132163

-
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_Hopengl_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() { }@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_viewMatrixseems not initialized when reaching this line?!What should
lookAtmultiply when there are no value? -
@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_viewMatrixseems not initialized when reaching this line?!What should
lookAtmultiply when there are no value?@Pl45m4
But the OP statesMy 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. -
@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.cppfile:// m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0)); -
@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.cppfile:// m_viewMatrix.lookAt(QVector3D(0, 0, 1), QVector3D(0, 0, 0), QVector3D(0, 1, 0));@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.
-
@Pl45m4
But the OP statesMy 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.@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 lineQMatrix4x4 m_viewMatrix;my example works -
@Pl45m4
But the OP statesMy 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.@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 onQMatrix4x4 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?
-
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.
-
@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 lineQMatrix4x4 m_viewMatrix;my example works@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.
-
-
@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.
@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_Hopengl_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_Hopengl_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 now the problem is gone. I don't understand why. I have attached my example here: https://discord.com/channels/457523061650882570/1247941120390991884/1247955899369132163

-
8 8Observer8 has marked this topic as solved on
-
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.