access violation reading location

Started by
14 comments, last by Evil Steve 13 years, 6 months ago
Quote:Original post by JohnnyCode
the window can be any size, while there are certain available resolutions for device. Set back buffer sizes to what ...


Actually, in windowed mode you can have any sized back buffer regardless of the display modes that the device supports.
Advertisement
1. As belfegor said, your card probably doesn't support D3DFMT_D24FS8 - the card caps spreadsheet that comes with the SDK shows that only a few ATI cards support that format.
You should be calling IDirect3D9::CheckDeviceFormat to see if a format is supported, and then IDirect3D9::CheckDepthStencilMatch to check that the depth buffer format can be used with the backbuffer format you've chosen.
I wrote a tutorial about this stuff, some of that might be useful.

2. Oddly, the debug runtimes don't tell you what's unsupported - usually they'll give a much more descriptive error than that...

3. I hope that GetMainWindow()->m_iWidth gives you the size of the client area, and not the sizes you passed to CreateWindow :P. You should be using AdjustWindowRect (See the tutotial code I linked above) to convert window size to client size, so your backbuffer and client area are the same size.
Ok, WOW is all I can say!! You all have given me a lot to work on and its great!!

Thank you Evil Steve for the link of those tutorials you created. There some of the best I have read online and in books. A few questions though.

Currently I am using CreateWindowEx, is there any reason why I should not use this and should use CreateWindow()?

I fixed the problem of setting the client window height and width to be the same as the buffers.

This is where I define the window and register it.
void CPlatform::Initialise(char* cAppName, int iXPos, int iYPos, int iWidth, int iHeight, int argc, char** argv){// Define the window  	memset(&wStructure,0,sizeof(wStructure)); //set the size of the window structure to 0   wStructure.cbSize         = sizeof( wStructure ); //initialize the count byte size of the window structure   wStructure.style          = CS_HREDRAW | CS_VREDRAW; //redraw when the window height or width changes   wStructure.lpfnWndProc    = WindowsProcedure;   wStructure.cbClsExtra     = 0;    wStructure.cbWndExtra     = 0;    wStructure.hInstance      = hInstance;    wStructure.hIcon          = NULL;    wStructure.hCursor        = NULL;    wStructure.hbrBackground  = (HBRUSH)GetStockObject( BLACK_BRUSH );  //  wStructure.lpszMenuName   = NULL;    wStructure.lpszClassName  = cAppName;   // wStructure.hIconSm        = LoadIcon( hInstance, IDI_APPLICATION );   // Register the window   if (!RegisterClassEx( &wStructure ))  {		  CLogger::Write("window register failed");  }  else	    c_pMainWindow= new CWindow(cAppName,iXPos,iYPos,iWidth,iHeight,hInstance);}


This is where I adjustwindow size and create the window
[source =lang"cpp"]CWindow::CWindow(char *cAppName, int iXPos, int iYPos, int iWidth, int iHeight,HINSTANCE hInstance){	m_iWidth = iWidth;	m_iHeight = iHeight;	/*	next i will use AdjustWindowRect to determine the window size based on the client area size;	*/	dwStyle = (WS_OVERLAPPEDWINDOW| WS_VISIBLE) & ~WS_THICKFRAME;	rc.top=rc.left=0;	rc.right = m_iWidth;	rc.bottom= m_iHeight;	AdjustWindowRect(&rc, dwStyle, FALSE);	sizeWindow.cx=rc.right - rc.left;	sizeWindow.cy=rc.bottom - rc.top;	m_windowHandle = CreateWindowEx(dwStyle, cAppName, cAppName, dwStyle, iXPos, iYPos, sizeWindow.cx,sizeWindow.cy, NULL, NULL, hInstance, this);}


At the moment my window will not show up. It just sits in the taskbar but when i try to view it nothing happens.

I have done all the D3DFORMAT checks now along with the device cap checks. This was from following the tutorials.Here is my Directx initialization:

bool CDirectx::Initialise(CPlatform * c_pPlatform){	//get direct3d pointer	g_p3DObject = Direct3DCreate9(D3D_SDK_VERSION);		//check if pointer was successful	if (!g_p3DObject)	{		CLogger::Write("could not get direct3d pointer");		return false;	}	//get current desktop format	hResult=g_p3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &g_displayMode);	if(FAILED(hResult))	{		CLogger::Write("get adapter display mode failed");		g_p3DObject->Release();		g_p3DObject=NULL;		return false;	}	fmtBackBuffer=g_displayMode.Format;		//Check to see what depth buffer supports	D3DFORMAT fmtDepths[] = {	D3DFMT_D32, 								D3DFMT_D24X8, 								D3DFMT_D24S8, 								D3DFMT_D24X4S4,								D3DFMT_D16,								D3DFMT_D15S1};	D3DFORMAT fmtDepthSelected = D3DFMT_UNKNOWN;	size_t nDepthFormats = sizeof(fmtDepths) / sizeof(fmtDepths[0]);	for (size_t i=0; i<nDepthFormats; ++i)	{		//see if we support the format		hResult= g_p3DObject->CheckDeviceFormat (D3DADAPTER_DEFAULT, 			D3DDEVTYPE_HAL,			g_displayMode.Format,			D3DUSAGE_DEPTHSTENCIL,			D3DRTYPE_SURFACE,			fmtDepths);		if(FAILED(hResult))		{			//graphics card does not support this format			continue;		}		//check if this format can be used with backbuffer format		hResult = g_p3DObject->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,			D3DDEVTYPE_HAL,			g_displayMode.Format,fmtBackBuffer,fmtDepths);		if(FAILED(hResult))		{			//graphics card does not support this z-buffer			continue;			}		//this format is usable		fmtDepthSelected=fmtDepths;		break;		}	if(fmtDepthSelected==D3DFMT_UNKNOWN)	{		return false;	}	D3DCAPS9 D3DCaps;	g_p3DObject->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &D3DCaps );	DWORD vertexProcessing = 0;	if ( D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )	{		vertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING;		// Check for pure device 		if ( D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE )		{			vertexProcessing |= D3DCREATE_PUREDEVICE;		}	}	else	{		vertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING;	}	m_iWidth=c_pPlatform->GetMainWindow()->m_iWidth;	m_iHeight=c_pPlatform->GetMainWindow()->m_iHeight;	D3DPRESENT_PARAMETERS d3dParam;	ZeroMemory (&d3dParam, sizeof (d3dParam));	d3dParam.Windowed =true;	d3dParam.EnableAutoDepthStencil=TRUE;	d3dParam.AutoDepthStencilFormat = fmtDepthSelected;	d3dParam.SwapEffect=D3DSWAPEFFECT_DISCARD;	d3dParam.BackBufferHeight=c_pPlatform->GetMainWindow()->sizeWindow.cy;	d3dParam.BackBufferWidth=c_pPlatform->GetMainWindow()->sizeWindow.cx;	d3dParam.BackBufferFormat=D3DFMT_X8R8G8B8;	d3dParam.BackBufferCount=1;		d3dParam.hDeviceWindow= c_pPlatform->GetMainWindow()->GetHandle();	if (FAILED( g_p3DObject->CreateDevice(D3DADAPTER_DEFAULT,											D3DDEVTYPE_HAL,											c_pPlatform->GetMainWindow()->GetHandle(),											vertexProcessing,											&d3dParam,											&g_p3DDevice)))	{		return false;	}	return true;}


I am not sure why my debugger is not ouputing more information. I checked it more than once to make sure the debug output level was to the max along with the other settings.

Thanks again to everyone that has been helping me work through this.
Quote:Original post by agisler
Ok, WOW is all I can say!! You all have given me a lot to work on and its great!!

Thank you Evil Steve for the link of those tutorials you created. There some of the best I have read online and in books.
Thanks! [smile]

Quote:Original post by agisler
Currently I am using CreateWindowEx, is there any reason why I should not use this and should use CreateWindow()?
Not really - CreateWindow is actually a macro that just calls CreateWindowEx with 0 as the first parameter. If you're not using the extended window styles, it doesn't make any difference at all.

Quote:Original post by agisler
At the moment my window will not show up. It just sits in the taskbar but when i try to view it nothing happens.
The first parameter to CreateWindowEx is the extended style, you should pass 0 for that (Your current style flags probably map to some totally unrelated extended flags).

Quote:Original post by agisler
I am not sure why my debugger is not ouputing more information. I checked it more than once to make sure the debug output level was to the max along with the other settings.
It looks like the output you get is normal - I tried it myself and that's the only output I get too. The debug runtimes are usually more helpful than that, it seems that this is all the output they give for unsupported formats unfortunately.
That did the trick!!

Everything seems like its running great now. I think my next step is to work on getting the window fullscreen and checking for lost device.

Thank you all so much!!
Quote:Original post by agisler
I think my next step is to work on getting the window fullscreen and checking for lost device.
Tutorial #3 [smile]

This topic is closed to new replies.

Advertisement