garrynewman / GWEN

Abandoned: GWEN - GUI Without Extravagant Nonsense.
MIT License
429 stars 102 forks source link

Update gwen/Samples/OpenGL/OpenGLSample.cpp #22

Closed ghost closed 11 years ago

ghost commented 11 years ago

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.

garrynewman commented 11 years ago

I disagree

sreich commented 11 years ago

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.