QPainter setFont segmentation fault on app exit.
-
I'm using OpenGL to draw stuff, some of them have text. Everything works, nothing is glitching, no crashes, it's just great. The only thing that is bothering me is when I close the app, it's throwing segmentation fault. Debugger shows nothing but assembly so that wasn't helpful. I was able to narrow it down to this function:
void OTUI::MainWindow::draw(QPainter& painter) { painter.save(); painter.setPen(getColor()); painter.setFont(getFont()); // this line is the reason //painter.setFont(QFont("Verdana", 11)); // same result painter.drawText(x(), y(), width(), 25, Qt::AlignCenter, getText()); painter.restore(); }
What to do? If you need more info, let me know.
-
@Christian-Ehrlicher Alright, started from scratch, adding as little code from previous project as possible. Made it so it's creating
OTUI::MainWindow
on startup, no seg fault. Started adding more, creation from context menu etc. and still no crash. Then added last pieces,StartupWindow
was one of them. It's a small window with list of recent projects that you can open or create new. It's a separated window that is opening second one (the one with OpenGL and all,CoreWindow
) and hiding itself. What I was missing is deleting 2nd window when the app is closed, insideStartupWindow
deconstructor.StartupWindow::~StartupWindow() { delete coreWindow; // this was missing delete ui; }
-
From where do you call MainWindow::draw()? And please provide some more code - best would be a minimal, compilable example.
-
@Christian-Ehrlicher From
QOpenGLWidget::paintGL
. You can clone project repository, nothing fancy needed to make it work straight away.
https://github.com/Oen44/OTUIEditorSegmentation fault occurs when you create at least
OTUI::MainWindow
widget, even if it's then deleted. To do this, create new project, right-click onWidgets List
panel on the left side and addMain Window
, then simply close the app (you will be asked if you want to save the project, just pressNo
), that's when segmentation fault happens. -
It would really be nice to get a small example - this will maybe also help you to find out the reason by yourself.
-
@Christian-Ehrlicher Alright, started from scratch, adding as little code from previous project as possible. Made it so it's creating
OTUI::MainWindow
on startup, no seg fault. Started adding more, creation from context menu etc. and still no crash. Then added last pieces,StartupWindow
was one of them. It's a small window with list of recent projects that you can open or create new. It's a separated window that is opening second one (the one with OpenGL and all,CoreWindow
) and hiding itself. What I was missing is deleting 2nd window when the app is closed, insideStartupWindow
deconstructor.StartupWindow::~StartupWindow() { delete coreWindow; // this was missing delete ui; }
-
Nice - good example why a minimal, compilable example is useful and good to track down the bug by yourself in most cases :)