CDialog::OnInitDialog(); crashes dialog in Debug

I am getting strange behaviour with launching a dialog in debug mode.  Sometimes it launches fine other times it crashes on the following line in the OnInit:
BOOL CWhichTeam::OnInitDialog()
        CDialog::OnInitDialog(); ------CRASHES HERE


If I step into the above function it will fail on:

Why could this be happening
Who is Participating?
mrjoltcolaConnect With a Mentor Commented:
It will affect your process memory a bit,  your process will require that much more memory, but for modern Windows Mobile, a 256k stack is not a problem.

You might check your classes to see if you are allocating large local buffers somewhere.

It is common for me to use old-fashioned C functions and I will always use large buffers.

char buf[4000];

but this can get you into trouble on small stack environments.
Wanting2LearnManAuthor Commented:
If I try to step into the SetForegroundWindow(m_hWnd) I get the below error:
You might actually need to increase the stacksize. I have had to do this on certain of my windows mobile applications, the default stack is not adequate in some cases. In your project properties, under linker, try doubling the Stack Reserver Size and see if this resolves it.
I meant "Stack Reserve Size"

You might try double, then quadruple. I think the default is 64k.

I often set mine to 256k for a major application, as I tend to create a lot of things, including dialogs, on the stack.
Wanting2LearnManAuthor Commented:
Yes this has solved this problem Thanks a lot. I will test it some more.  I was getting weird errors where it I launched a dialog from one part of my code it would launch ok but if I launched the same dialog from another part of the code (deeper down, if you know what I mean) then I would get the above error.  
Does this sound familiar???

My Stack size was set to the default like you suggested so I doubled it.  Should this be enough?

If I set it to e.g. 256k would this affect anything??

Thanks a lot :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.