Can't find the invalid pointer
-
@nagesh I still get error but is a different message
The inferior stopped because it received a signal from the operating system. Signal name : SIGABRT Signal meaning : Aborted
I get this error in
Facelet::~Facelet()
and the console application displaysmunmap_chunk(): invalid pointer
.
I also tried to turnfacelets
into aFacelet***
and treatFacelet[i][j]
as a pointer instead as an object, but I get the same error I got at the begin -
@Gallo-Magico do you still get these errors when you are not deleting/freeing?
//__delete_facelets(); //delete layout;
-
@Gallo-Magico said in Can't find the invalid pointer:
MainWindow::~MainWindow()
{
delete spacer;
delete object;
delete layout;
delete wid;
}Same problem here. If
QObject
s have a parent they get deleted when the parent gets deleted automatically, if you do it manually it's a double deletion.
If debugging is becoming a mess change the type of yourQObject
s pointer toQPointer
so the pointers will be set to null automatically on deletion and you won't be able to double-delete them -
@VRonin said in Can't find the invalid pointer:
Same problem here. If QObjects have a parent they get deleted when the parent gets deleted automatically, if you do it manually it's a double deletion.
No it is not. The child notifies the parent when it goes away, so the parent detaches it from the list.
-
@kshegunov said in Can't find the invalid pointer:
No it is not. The child notifies the parent when it goes away, so the parent detaches it from the list.
@VRonin forgot a sentence in
if you do it manually it's a double deletion.
- if you do it manually after the parent deleted it's children it's a double deletion :) -
I figured out,there were a bounch of problem, first of all I used to double delete child widgets, like the layout(child of the main widget) and the other widget into the layout(child of the layout), then I got all my destructors empty but I got an error caused by deleting a location memory not allocated with new. In my case the dynamic matrix of facelet don't allocate the memory for each Facelet, then I turned facelets from
Facelet** facelets
into aFacelet*** facelets
and changedinit_facelets()
tovoid Face::init_facelets() { facelets = new Facelet**[3]; for(int i = 0; i < 3; ++i) { facelets[i] = new Facelet*[3]; for(int j = 0; j < 3; ++j) { facelets[i][j] = new Facelet(); } } }
When the program ends,
Face::~Face()
frees all the location corresponding tofacelets[i][j]
, then I had to free the rest of the matrix, so nowFace::~Face()
looks likeFace::~Face() { for(int i = 0; i < 3; ++i) { delete[] facelets[i]; } delete[] facelets; }
Now it works with no problem or any issue
-
@Gallo-Magico said in Can't find the invalid pointer:
layout->addWidget(&facelets[i][j]
This sets
Face
as parent offacelets[i][j]
so same error as before you are double deleting aQObject
as the parent already deleted itNo it is not. The child notifies the parent when it goes away, so the parent detaches it from the list.
Good observation, I didn't explain myself well there.
P.S.
from https://en.cppreference.com/w/cpp/keyword- identifiers with a double underscore anywhere are reserved
- identifiers that begin with an underscore followed by an uppercase letter are reserved
You should rename your methods/members