Current object is deleted but continues executing accessing invalid memory
Posted on 2006-03-22
Looking at my simplified code below (nothing to do with MFC), basically what I believe is happening is that this method is entered, the messagehandler in the code is called on another object which in turn this object get's deleted (when needed). Obviously if this object does get deleted the problem now is that this method continues executing but m_bComplete no longer exists and therefore causes an access violation error! Is there anyway to check whether this object is still valid at this point? or is there a method to get around this?
Many thanks in advance!
void Button::OnLeftMouseButtonDown(int x, int y, WPARAM status)
// Send a 'Left Mouse Button Down Single Click' message to the respective
// message handler
m_pObjectToReceiveMessages->MessageHandler(GetName(), LEFT_MOUSE_BUTTON_DOWN_SINGLE_CLICK, NULL);
m_bComplete = true;