MessageBox(), D3D conflict?

Started by
9 comments, last by Jkom329 15 years, 11 months ago
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]
Advertisement
Could you provide a code snippet? I wonder if its a problem with using a window handle for two different purposes. Hmm...
------------Anything prior to 9am should be illegal.
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;
}
=======================================
It does work if I pass a window handle... I still wonder why the NULL parameter causes problems though.
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.
Yeah, you're better off passing the window handle for the reason andur said.. God knows why it was crashing with NULL though.
In what way does it crash? Are you using the Debug Runtimes? Any relevant output from them before the crash? Have you tried calling IDirect3DDevice9::SetDialogBoxMode(TRUE)?
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.
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.
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.

This topic is closed to new replies.

Advertisement