Sign in to follow this  

MessageBox(), D3D conflict?

This topic is 3488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I call MessageBox() after d3d::InitD3D(), my program crashes. If I call it before InitD3D, everything works just fine. Is there some known conflict here? I recently updated my compiler to Visual Studio 2008 express all the way from 6.0. I don't think I ever had this problem from programs compiled on 6.0. Weird. Someone please enlighten me. EDIT: Bah. That d3d::InitD3D() is my own function. I refer to it above as if it were in the SDK. Lets just say that after I initialize my IDirect3DDevice9, MessageBox() crashes. [Edited by - Jkom329 on May 26, 2008 5:09:27 PM]

Share this post


Link to post
Share on other sites
Sure. This is a simplified version of what does not work. I'm using NULL for the hwnd parameter here, but that shouldn't matter as far as I know... I may as well experiment to see if it does work with a window handle though. I'll let you know.

====================================
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
if(!d3d::InitD3D(hInstance, DEFAULT_WIDTH, DEFAULT_HEIGHT, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(NULL, "InitD3D() - FAILED",0, 0);
return 0;
}

::MessageBox(NULL, "I crash the program.",0, 0);
=======================================

But this does work
====================================
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
::MessageBox(NULL, "I do NOT crash the program.",0, 0);

if(!d3d::InitD3D(hInstance, DEFAULT_WIDTH, DEFAULT_HEIGHT, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(NULL, "InitD3D() - FAILED",0, 0);
return 0;
}
=======================================

Share this post


Link to post
Share on other sites
It should be safe. I use MessageBox with a NULL Handle and I don't crash d3d. What it might be, is in fullscreen mode you won't see the MessageBox (your app will be rendered on top of it), you can still hit enter though and close the MessageBox.

Share this post


Link to post
Share on other sites
It's just a flat out crash right in the beginning. I get the "has encountered a problem and needs to close." This happens in both release and debug builds. If I run the program through the debugger, I get the following

Unhandled exception at 0x00405aaa in XXXX.exe: 0xC0000005: Access violation reading location 0x00000000.

I tried calling SetDialogBoxMode, and that did not change anything. Note that I am running this program in windowed mode.

There may be some deeper problems here that are causing simple things like MessageBox to fail... I've got another problem with this program that I haven't completely nailed down yet. I'm getting close though, so we'll see if fixing that problem fixes the MessageBox problem.

Share this post


Link to post
Share on other sites
It was a deeper problem as I thought. I was playing with some bad pointers in more than one spot. Took me several hours to track it all down. It's probably not useful to go into details, so I'll just say that I'm glad that's over.

I do have another minor concern though. As I said, the message boxes work and do not crash my program, but now when I use the MessageBox function after initializing d3d, the boxes do not appear in the foreground. Note that I am running the program in windowed mode.

It's not a big deal really. I just find the MB's convenient for debugging purposes sometimes. After dealing with the pointer issues I just described, I'll be quite content with the background appearances. Just curious.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jkom329
I do have another minor concern though. As I said, the message boxes work and do not crash my program, but now when I use the MessageBox function after initializing d3d, the boxes do not appear in the foreground. Note that I am running the program in windowed mode.

It's not a big deal really. I just find the MB's convenient for debugging purposes sometimes. After dealing with the pointer issues I just described, I'll be quite content with the background appearances. Just curious.
Are you passing your main window handle as the HWND parameter to MessageBox()? If so, it should Just Work, unless you're doing strange things like setting your app window to WS_TOPMOST or something similar.

Share this post


Link to post
Share on other sites
Yep. That's exactly what I was doing. I remembered setting TOPMOST as soon as I read your post. This is what happens when I don't work on a project for a while. I forget what I did and why I did it.

Share this post


Link to post
Share on other sites

This topic is 3488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this