What does this error mean?
-
I am trying to debug my program because while running my driver program i encounter a bug and the error that the computer tells me is this: " Unhandled Exception in Tictactoe.exe: 0x000005: Access violation" this error occurred in my destructor for my CBoard Class CBoard::~CBoard() { delete mpDefaultPen; <-- what is causing a exception to be thrown? } oh i used this pointer in my function // Changes the Line color to the value entered void CBoard::SetLineColor(CDC* pDC, COLORREF color) { // Sets color to mLine color mLineColor= color; // Construct a pen mpPen = new CPen; VERIFY(mpPen); VERIFY(mpPen->CreatePen(PS_SOLID,5,mLineColor)); VERIFY(mpDefaultPen = pDC->SelectObject(mpPen)); <-- rite here } Does anyone know whats causing this bug to occur? anyways... thank you in advance for helping me... i very much appreciate all the help ;) :) :)
-
I am trying to debug my program because while running my driver program i encounter a bug and the error that the computer tells me is this: " Unhandled Exception in Tictactoe.exe: 0x000005: Access violation" this error occurred in my destructor for my CBoard Class CBoard::~CBoard() { delete mpDefaultPen; <-- what is causing a exception to be thrown? } oh i used this pointer in my function // Changes the Line color to the value entered void CBoard::SetLineColor(CDC* pDC, COLORREF color) { // Sets color to mLine color mLineColor= color; // Construct a pen mpPen = new CPen; VERIFY(mpPen); VERIFY(mpPen->CreatePen(PS_SOLID,5,mLineColor)); VERIFY(mpDefaultPen = pDC->SelectObject(mpPen)); <-- rite here } Does anyone know whats causing this bug to occur? anyways... thank you in advance for helping me... i very much appreciate all the help ;) :) :)
You shouldn't
delete
mpDefaultPen
, but rather select it back topDC
withSelectObject
once you're done with the DC object. Check your documentation forSelectObject
. The general scheme is as follows:mpDefaultPen =pDC->SelectObject(mpPen);
// drawing stuff, whatever
pDC->SelectObject(mpDefaultPen); // done with pDC, revert to original stateJoaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
You shouldn't
delete
mpDefaultPen
, but rather select it back topDC
withSelectObject
once you're done with the DC object. Check your documentation forSelectObject
. The general scheme is as follows:mpDefaultPen =pDC->SelectObject(mpPen);
// drawing stuff, whatever
pDC->SelectObject(mpDefaultPen); // done with pDC, revert to original stateJoaquín M López Muñoz Telefónica, Investigación y Desarrollo
oh ok thank you Joaquin for the help. i forgot, i didnt create mpDefaultPen so i shouldnt delete it or it will cause me an error (i forgot what kind of error that is -- i think its the dangling pointer problem). again thank you for your help :) muchas gracias para me ayudarle :) is what is said right?? :) :) :)
-
oh ok thank you Joaquin for the help. i forgot, i didnt create mpDefaultPen so i shouldnt delete it or it will cause me an error (i forgot what kind of error that is -- i think its the dangling pointer problem). again thank you for your help :) muchas gracias para me ayudarle :) is what is said right?? :) :) :)
muchas gracias para me ayudarle :) is what is said right?? It's close. The correct sentence would be "Muchas gracias por ayudarme". You are welcome. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo