Closed ghost closed 11 years ago
I disagree
yes, this makes no sense.
you have: if(!pCanvas) delete pCanvas;
which doesn't make sense, because that means "if canvas has been deleted, delete the canvas". what you really meant to have was if (pcanvas) delete pcanvas;. But that also doesn't make sense and is a common mistake.
double deletes are perfectly fine in C++, provided the pointer is zeroed out after the first delete. so checking if it's been deleted is superfluous.
if you're encountering issues, the problem is elsewhere, perhaps by not zeroing out a pointer. use valgrind to pinpoint.
The two "delete" at the end of the file causes the program to crash due to it trying to delete NULL pointers.
They should always be NULL by the time it reaches that point, but if for some bizarre reason they're not, we might as well delete them ONLY if !NULL.