Seg fault when deleting Q3DScatter object
-
Thank you for a reply, I am familiar with gdb stack trace and was hoping to see it, but at the time of the crash, textual log doesn't contain anything that resembles it, and even stack in QT is empty. But it might not be enabled by default, and I can't find a way to enable it.
I look into getting a stack trace from gdb
-
@vedranMv
I am not used to seeing anything like the textual output you show when running/debugging inside Qt Creator. Is that what you are doing? Normally then the Creator debugger windows handle all of this, you don't need to look at "gdb output".and even stack in QT is empty
Show screenshot of what you mean here?
-
@JonB Yes, I simply press on the debug button inside QT creator. The view looks something like:
I might've pressed something to add the two windows with textual output on top. If I remember correctly they were not there by default.
Blue arrow shows what I refer to as "QT stack being empty". I'm used to seeing a call stack in here, but when the issue happens, it shows '??' -
@vedranMv
Why are you in the Disassembler pane? I think use the up/down arrows there to pick the "stack trace" pane? Find & show that, even if it turns out the stack is corrupted (which can happen), at least let's see the appropriate pane. I don't recognise your layout/the top pane, but then I am Qt Creator/gdb/gcc under Linux. -
@JonB Thanks for suggestion. That's where I'm taken when fault happens. I guess it means that fault is thrown in some of the libraries, which can't be tracked? If I use the left/right arrows, I get taken back to another dissasembly screen when pressing left arrow for the first time, then back to whatever document I edited the last, when pressed for the second time.
I have been playing with destructor of ScatterPlot class. If I leave it empty or make it like this, I get seg fault:
ScatterPlot ::~ScatterPlot () { m_graph->seriesList().clear(); m_graph->close(); m_graph->deleteLater(); }
If I instead directly call m_graph's destructor, seg fault is not happening.
ScatterPlot ::~ScatterPlot () { m_graph->seriesList().clear(); m_graph->close(); m_graph->~Q3DScatter(); }
-
Hi,
Might be a silly question but are you sure you are using a debug build ?
-
I have uploaded the code to github, in case anybody is interested in trying it out: https://github.com/vedranMv/dataDashboard/
There's a branch called segfault which in combination with the description above creates the fault. To recap, steps are:
- Run the app
- In the Dashboard tab press "Add 3D" button
- In the Dashboard tab press "Add scatter" button
- Press 'X' to close scatter window
- Enjoy the segfault
There's also what I believe is a fix, but I'd like to understand why it works. Documentation and general recommendation is to use deleteLater() instead, but that also results in a segfault :)
-
Ouch, that hurts! Why do you explicitly call the destructor?
If you do want to free the memory (and do you?) usedelete _graph
. Did you set a parent to yourQ3DScatter
instance? If you did, then it will be deleted for you.Edit:
@vedranMv said in Seg fault when deleting Q3DScatter object:There's also what I believe is a fix, but I'd like to understand why it works. Documentation and general recommendation is to use deleteLater() instead, but that also results in a segfault :)
Then it means you're most probably deleting twice the instance: the first time with your dicey call to the destructor / or
deleteLater
, and the second when the parent object gets deleted. -
@JohanSolo Thanks, I for some reason did not think of using delete here at all :D That works just as good!
Regarding your edit, what you're writing makes perfect sense, but as you can see in the code, it's the other way around. If I don't call
delete
manually, I get a segfault. And yes, object gets a parent because I encapsulate it into a container widget, which is then added into the UI window. -
@vedranMv said in Seg fault when deleting Q3DScatter object:
Regarding your edit, what you're writing makes perfect sense, but as you can see in the code, it's the other way around. If I don't call
delete
manually, I get a segfault.Then it seems to me there must be something else wrong in your code.