invalidate()/updatewindow() debug vs. release
Hello,
Thank you for taking the time from your busy day to help me out.
I'm running the invalidate()/Updatewindow() combo to refresh a dialog box. This crashes the program in debug mode but runs fine in release mode.
void Status::repaintstatus()
{
Invalidate();
UpdateWindow();
}
I've read a few debug vs release mode articles but could not find a solution to this error. Again, thank you very much for your time.
Greg
Re: invalidate()/updatewindow() debug vs. release
Not enough info. There's nothing in that code that should cause a crash. Use the debugger to examine your locals, particularly the this pointer. Something's getting messed up upstream.
Re: invalidate()/updatewindow() debug vs. release
Oh wow. The this pointer was getting corrupted as it turns out I was calling these functions while the dialog box wasn't even enabled!!! I don't know what I was thinking and I don't why release mode wouldn't catch this...haha. Thank you very much. The dialog box these functions are being used on is a popup dialog box. Do you know of a way to check when the dialog box is enabled? I found the IsWindowEnabled() function but I'm guessing I somehow need to make a pointer to the CWnd* in the constructor? Any help with that would be much appreciated. Again thank you very much.
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
Gregorina
Oh wow. The this pointer was getting corrupted as it turns out I was calling these functions while the dialog box wasn't even enabled!!! I don't know what I was thinking and I don't why release mode wouldn't catch this...haha. Thank you very much. The dialog box these functions are being used on is a popup dialog box. Do you know of a way to check when the dialog box is enabled? I found the IsWindowEnabled() function but I'm guessing I somehow need to make a pointer to the CWnd* in the constructor? Any help with that would be much appreciated. Again thank you very much.
IsWindowEnabled() is a member of CWnd. You can call it anywhere inside your dialog, or through any instance of a CWnd derived class. Windows still paint whether they're enabled or not, so that's probably not what you're looking for. Do you mean you had a CDialog object that didn't have an associated window yet? If so, use IsWindow().
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
Gregorina
Do you know of a way to check when the dialog box is enabled? I found the IsWindowEnabled() function but I'm guessing I somehow need to make a pointer to the CWnd* in the constructor? Any help with that would be much appreciated. Again thank you very much.
If you call the function outside a scope where you are sure the window exists, you can use
Code:
void Status::repaintstatus()
{
if (IsWindow(GetSafeHwnd()) {
Invalidate();
UpdateWindow();
}
}
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
GCDEF
IsWindowEnabled() is a member of CWnd. You can call it anywhere inside your dialog, or through any instance of a CWnd derived class. Windows still paint whether they're enabled or not, so that's probably not what you're looking for. Do you mean you had a CDialog object that didn't have an associated window yet? If so, use IsWindow().
Yes there was no window for the Status CDialog. I am using IsWindow(GetSafeHwnd()) as Drmmr suggested, but even though the Status dialog has a window, IsWindow(GetSafeHwnd()) still returns 0 and the if statement isn't entered. I'm not really sure when the dialog box will have a window, that's why I'm checking. Maybe it would be easier to set a flag in the oninitdialog? Then I would have to reset the flag when the dialog box is gone, what virtual function would I use for that?
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
Gregorina
Yes there was no window for the Status CDialog. I am using IsWindow(GetSafeHwnd()) as Drmmr suggested, but even though the Status dialog has a window, IsWindow(GetSafeHwnd()) still returns 0 and the if statement isn't entered. I'm not really sure when the dialog box will have a window, that's why I'm checking. Maybe it would be easier to set a flag in the oninitdialog? Then I would have to reset the flag when the dialog box is gone, what virtual function would I use for that?
Unless you override the default behavior, the window is created in OnInitDialog, and destroyed in EndDialog. Are you calling IsWindow inside or outside the dialog?
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
GCDEF
Unless you override the default behavior, the window is created in OnInitDialog, and destroyed in EndDialog. Are you calling IsWindow inside or outside the dialog?
I'm calling it inside the status dialog class, but the dialog may not necessarily be created yet from the parent dialog. Actually I added a flag to set after the status dialog box is created:
Code:
void Status::repaintstatus()
{
if(check)
{
Invalidate();
UpdateWindow();
}
}
But even though the dialog box is created Invalidate() still crashes the program. I know the this pointer is getting corrupted somewhere, but I can't find where. This code was given to me at work and was written by someone else and it has threads and is about 20000 lines of code. It's hard to step through. Is there a way in the debugger to add a variable to the watch and then skip ahead to where the value of that variable changes?
Re: invalidate()/updatewindow() debug vs. release
Just set a breakpoint, right click on the red dot, select condition, then select when changed.
Re: invalidate()/updatewindow() debug vs. release
It gets corrupted on the Status status; line.
Code:
Status status;
if(condition)
{
status.repaintstatus();
}
Code:
void Status::repaintstatus()
{
if(check)
{
Invalidate();
UpdateWindow();
}
}
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
Gregorina
It gets corrupted on the Status status; line.
Code:
Status status;
if(condition)
{
status.repaintstatus();
}
Code:
void Status::repaintstatus()
{
if(check)
{
Invalidate();
UpdateWindow();
}
}
What gets corrupted? The this pointer for status class instance? If this is right, then the constructor for Status class is a likely candidate for the corruption problem.
Re: invalidate()/updatewindow() debug vs. release
Quote:
Originally Posted by
Gregorina
It gets corrupted on the Status status; line.
Code:
Status status;
if(condition)
{
status.repaintstatus();
}
What is your Status? Is it a dialog? It is not enough to construct dialog object, you need to create its window.