-
December 10th, 2013, 06:55 PM
#1
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
-
December 10th, 2013, 07:02 PM
#2
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.
-
December 10th, 2013, 08:34 PM
#3
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.
-
December 10th, 2013, 09:21 PM
#4
Re: invalidate()/updatewindow() debug vs. release
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().
-
December 11th, 2013, 02:35 AM
#5
Re: invalidate()/updatewindow() debug vs. release
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();
}
}
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
December 11th, 2013, 01:06 PM
#6
Re: invalidate()/updatewindow() debug vs. release
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?
-
December 11th, 2013, 01:21 PM
#7
Re: invalidate()/updatewindow() debug vs. release
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?
-
December 11th, 2013, 01:40 PM
#8
Re: invalidate()/updatewindow() debug vs. release
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?
Last edited by Gregorina; December 11th, 2013 at 05:37 PM.
-
December 11th, 2013, 01:57 PM
#9
Re: invalidate()/updatewindow() debug vs. release
Just set a breakpoint, right click on the red dot, select condition, then select when changed.
-
December 11th, 2013, 05:29 PM
#10
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();
}
}
-
December 11th, 2013, 05:45 PM
#11
Re: invalidate()/updatewindow() debug vs. release
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 12th, 2013, 03:22 PM
#12
Re: invalidate()/updatewindow() debug vs. release
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.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|