Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3D9 Window being created and then destroyed

Started by Emexus Aug 13, 2006 at 10:25 AM 9 replies 2.7k views
Original Post
Emexus
Emexus
Just been following the d3d9 tutorial from here: http://www.gamedev.net/reference/articles/article1943.asp and compiled it, it all runs and the window is created but after about a second the window is destroyed and the only output in the debug window is:

Direct3D9: (ERROR) :    [0] : Address 00A3D4CB
Direct3D9: (ERROR) :    [1] : Address 00A3D59B
Direct3D9: (ERROR) :    [2] : Address 00A3D440
Direct3D9: (ERROR) :    [3] : Address 00A31D44
Direct3D9: (ERROR) :    [4] : Address 4FDFAF2E
Direct3D9: (ERROR) :    [5] : Address 00411455
Direct3D9: (ERROR) :    [6] : Address 00411969
Direct3D9: (ERROR) :    [7] : Address 00412136
Direct3D9: (ERROR) :    [8] : Address 00411E9D
Direct3D9: (ERROR) :    [9] : Address 7C816FD7
Direct3D9: (ERROR) :    [10] : Address 00000000
Direct3D9: (ERROR) :    [11] : Address 00000000
Direct3D9: (ERROR) :    [12] : Address 00000000
Direct3D9: (ERROR) :    [13] : Address 00000000
Direct3D9: (ERROR) :    [14] : Address 00000000
Direct3D9: (ERROR) :    [15] : Address 00000000
any ideas on what this could be?
DarkZoulz
DarkZoulz
Quote:
Original post by Emexus

Direct3D9: (ERROR) :    [0] : Address 00A3D4CBDirect3D9: (ERROR) :    [1] : Address 00A3D59BDirect3D9: (ERROR) :    [2] : Address 00A3D440Direct3D9: (ERROR) :    [3] : Address 00A31D44Direct3D9: (ERROR) :    [4] : Address 4FDFAF2EDirect3D9: (ERROR) :    [5] : Address 00411455Direct3D9: (ERROR) :    [6] : Address 00411969Direct3D9: (ERROR) :    [7] : Address 00412136Direct3D9: (ERROR) :    [8] : Address 00411E9DDirect3D9: (ERROR) :    [9] : Address 7C816FD7Direct3D9: (ERROR) :    [10] : Address 00000000Direct3D9: (ERROR) :    [11] : Address 00000000Direct3D9: (ERROR) :    [12] : Address 00000000Direct3D9: (ERROR) :    [13] : Address 00000000Direct3D9: (ERROR) :    [14] : Address 00000000Direct3D9: (ERROR) :    [15] : Address 00000000



Those errors refer to memory that has not been deallocated correctly. But it gives no clue to why your program is exiting prematurely. Maybe you could post some of the code. The main loop perhaps.
Emexus
Emexus
heres all the code from the app

#include <windows.h>#include <d3D9.h>#include <d3dx9.h>IDirect3D9* pD3D9 = NULL;IDirect3DDevice9* pD3DDevice9 = NULL;HRESULT InitDirect3D(HWND hWnd, int width, int height, bool fullscreen){	pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);	if(pD3D9 == NULL)		return E_FAIL;	// display mode	D3DDISPLAYMODE d3ddm;	pD3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);	// presentation settings	D3DPRESENT_PARAMETERS d3dpp;	ZeroMemory(&d3dpp, sizeof(d3dpp));	d3dpp.BackBufferWidth = width;	d3dpp.BackBufferHeight = height;	d3dpp.BackBufferCount = 1;	d3dpp.BackBufferFormat = d3ddm.Format;	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	d3dpp.Windowed = !fullscreen;	d3dpp.EnableAutoDepthStencil = true;	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;	if(FAILED(pD3D9->CreateDevice(D3DADAPTER_DEFAULT, 								  D3DDEVTYPE_HAL, hWnd, 								  D3DCREATE_HARDWARE_VERTEXPROCESSING, 								  &d3dpp, &pD3DDevice9)))	{		return E_FAIL;	}	return S_OK;}void Render(void){	pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);	pD3DDevice9->BeginScene();	// Draw code	pD3DDevice9->EndScene();	pD3DDevice9->Present(NULL, NULL, NULL, NULL);}void DestroyD3D(void){	if(pD3DDevice9)	{		pD3DDevice9->Release();		pD3DDevice9 = NULL;	}	if(pD3D9)	{		pD3D9->Release();		pD3D9 = NULL;	}}LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam){    switch(Msg)    {        case WM_CLOSE:	      DestroyD3D();	      UnregisterClass(g_szClassName, hInstance);              DestroyWindow(hWnd);        break;        case WM_DESTROY:              PostQuitMessage(0);        break;        default:            return DefWindowProc(hWnd, Msg, wParam, lParam);    }    return 0;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdLine, int CmdShow){	WNDCLASSEX windowClass;	MSG Msg;	HWND hWnd = NULL;	static TCHAR g_szClassName[] = TEXT("DXWindowClass");	// class struct	windowClass.cbSize        = sizeof(WNDCLASSEX);	windowClass.style         = CS_HREDRAW | CS_VREDRAW;	windowClass.lpfnWndProc   = WndProc;	windowClass.cbClsExtra    = 0;	windowClass.cbWndExtra    = 0;	windowClass.hInstance     = hInstance;	windowClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);	windowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);	windowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);	windowClass.lpszMenuName  = NULL;	windowClass.lpszClassName = g_szClassName;	windowClass.hIconSm       = LoadIcon(NULL, IDI_WINLOGO);	if(!RegisterClassEx(&windowClass))		return 0;	hWnd = CreateWindowEx(NULL, g_szClassName, TEXT("dx_render"), 		                  WS_OVERLAPPEDWINDOW | WS_VISIBLE, 						  0, 0, 800, 600, 						  NULL, NULL, hInstance, NULL);	if(!hWnd)		return 0;	if(FAILED(InitDirect3D(hWnd, 800, 600, false)))	{		DestroyD3D();		return 0;	}	while(1)	{		PeekMessage(&Msg, hWnd, NULL, NULL, PM_REMOVE);		if(Msg.message = WM_QUIT)			break;		else		{			Render();			TranslateMessage(&Msg);			DispatchMessage(&Msg);		}		return ((int)Msg.wParam);	}	return 0;}
Sol462
Sol462
You should have a ShowWindow call after you create the window methinks.

Also, try to put long segments of code into [ code] tags. It makes it a bit easier to read your code.
Emexus
Emexus
Just tried ShowWindow and it makes no difference the window is stil created and displayed and then suddenly destroyed?
Scet
Scet
if(Msg.message = WM_QUIT)

Your loop breaks right away because you're assigning WM_QUIT to Msg.message. You want ==.
DarkZoulz
DarkZoulz
Hmm.. you have a return in your while-loop. That would cause your WinMain to exit and is probably the answer to why the window just gets created and destoryed. Try to remove it and I think it should work fine.

	while(1)	{		PeekMessage(&Msg, hWnd, NULL, NULL, PM_REMOVE);		if(Msg.message = WM_QUIT)			break;		else		{			Render();			TranslateMessage(&Msg);			DispatchMessage(&Msg);		}		HERE >>> return ((int)Msg.wParam); <<< HERE	}

DarkZoulz
DarkZoulz
Quote:
Original post by Scet
if(Msg.message = WM_QUIT)

You're loop breaks right away because you're assigning WM_QUIT to Msg.message. You want ==.


That's true too.
Emexus
Emexus
excellent thankyou i cant belived i overlooked thoes lol. so that problem is fixed but i have a new error.

now when it runs it comes up with unhandled exception at 0x00411608 in dx_render.exe

and is identifying this line:

	pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
Sol462
Sol462
That line's correct. The only thing I've done differently was cleared the zbuffer in addition to the target, but that shouldn't affect anything.
Endurion
Endurion
Not related to the crash, but remove the hWnd from the PeekMessage call. You will not receive WM_QUIT if you leave it in there.

WM_QUIT is posted to your thread's message queue, not to any particular window.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.