Jump to content
  • Advertisement
Sign in to follow this  
agisler

access violation reading location

This topic is 2808 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

Hi,

All of a sudden I have been getting an error at my EndScene and Present. I have spent the last day trying to figure this out but have had no luck. The project builds with no errors but when I run it I get an error "Unhandled exception at 0x011b1a4f in Ping.exe: 0xC0000005: Access violation reading location 0x00000000".

The error happens on the EndScene.

void CDirectx::EndFrame()
{

g_p3DDevice->EndScene();
g_p3DDevice->Present(NULL,NULL,NULL,NULL);
}


The only thing I have changed recently is I have added another class. I have commented the class out so as far as I know thats not the problem.


Many Thanks

Share this post


Link to post
Share on other sites
Advertisement
Thanks again Evil Steve!! Its great how you can spot the problem but if its staring me in the face I am blind as a bat. :)

The problem was in where I created my device.



if (FAILED( g_p3DObject->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
c_pPlatform->GetMainWindow()->GetHandle(),
vertexProcessing,
&d3dParam,
&g_p3DDevice)))



The problem was that I was using D3DDEVTYPE_HAL instead of D3DDEVTYPE_REF like above.

I looked up the differences and from what I read D3DDEVTYPE_REF should only be used for development purposes. So why might I be getting errors with hal? I rather fix these things now than face bigger problems in the future.

Many thanks once again.

Share this post


Link to post
Share on other sites
What do the Debug Runtimes say? If CreateDevice() fails with HAL but succeeds with REF, it's usually because you're trying to use a feature that your card doesn't support. You should be checking the device caps for everything you need, so you know if a function is likely to fail. You should also be able to gracefully handle "major" functions like CreateDevice() failing, and abort the program and display an error the the user.

The REF device is a software renderer, that's designed to be a "perfect" GPU / driver - it'll implement everything possible, but it'll be extremely slow. The only time you should be using it is if you're checking up on a potential driver bug (If the results from a HAL and REF device differ, REF is always right), or if you're trying to develop a feature that your graphics card doesn't support (E.g. if you needed to use pixel shaders but your dev PC only had a GeForce 2)

Share this post


Link to post
Share on other sites
Thanks for the advice. I am going to spend a lot of time doing checking the device caps.

My debug runtime says:

D3D9 Helper: IDirect3D9::CreateDevice failed: D3DERR_NOTAVAILABLE

Isn't my D3DERR a library file or dll file?

How come my return is not being called when the device does fail?


if (FAILED( g_p3DObject->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
c_pPlatform->GetMainWindow()->GetHandle(),
vertexProcessing,
&d3dParam,
&g_p3DDevice)))
{
return;
}



Thanks for the explanation on HAL and REF. That all makes a lot of sense now.


Many Thanks

agisler

Share this post


Link to post
Share on other sites
Quote:
MSDN Docs
D3DERR_NOTAVAILABLE
This device does not support the queried technique.


I did once have a laptop that didn't support hardware vertex processing but that is a bit unlikely.

Could you post your D3DPRESENT_PARAMS set up? It's probable that you are requesting something in there that the hardware doesn't support.

You'll also find it easier to track this stuff if you actually respond to a positive from the FAILED() macro with an error message rather than just ignoring the result.

Share this post


Link to post
Share on other sites
In addition to what Aardvajk said; make sure your debug output level in the DirectX Control Panel is set to maximum - you should get more information than that, telling you exactly what is unavailable. Can you paste your entire debug output?

Share this post


Link to post
Share on other sites
Hi,

Sorry about taking so long to get back. This is what was in my debug window....

'Ping.exe': Loaded 'C:\CODEBASE\ANDREW_GISLER\Ping\Debug\Ping.exe', Symbols loaded.
'Ping.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\d3d9.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\d3d8thk.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Ping.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\avgrsstx.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\d3d9d.dll', Cannot find or open the PDB file
'Ping.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
Direct3D9: :====> ENTER: DLLMAIN(6820d9a0): Process Attach: 000009fc, tid=00000ff0
Direct3D9: :====> EXIT: DLLMAIN(6820d9a0): Process Attach: 000009fc
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.
'Ping.exe': Loaded 'C:\Windows\System32\nvd3dum.dll', Cannot find or open the PDB file
D3D9 Helper: IDirect3D9::CreateDevice failed: D3DERR_NOTAVAILABLE
First-chance exception at 0x009e1a9f in Ping.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x009e1a9f in Ping.exe: 0xC0000005: Access violation reading location 0x00000000.


Here is my code for initialising my parameters and etc.

g_p3DObject = Direct3DCreate9(D3D_SDK_VERSION);
if (!g_p3DObject)
{

}
m_iWidth=c_pPlatform->GetMainWindow()->m_iWidth;
m_iHeight=c_pPlatform->GetMainWindow()->m_iHeight;

g_p3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &g_displayMode);

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;
}

D3DPRESENT_PARAMETERS d3dParam;
ZeroMemory (&d3dParam, sizeof (d3dParam));
d3dParam.Windowed =true;
d3dParam.AutoDepthStencilFormat = D3DFMT_D24FS8;
d3dParam.EnableAutoDepthStencil=TRUE;
d3dParam.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dParam.BackBufferFormat=D3DFMT_X8R8G8B8;
d3dParam.BackBufferCount=1;
d3dParam.BackBufferHeight=m_iHeight;
d3dParam.BackBufferWidth=m_iWidth;
d3dParam.hDeviceWindow= c_pPlatform->GetMainWindow()->GetHandle();



Quote:

You'll also find it easier to track this stuff if you actually respond to a positive from the FAILED() macro with an error message rather than just ignoring the result.

If i understand this correctly your saying that I should do something other than just simply using the return keyword? I was planning on putting something there more significant at a later time. Its just there for temporary purposes.

Thanks again for all the help.

Share this post


Link to post
Share on other sites
It is most likely that your hw/device doesn't support D24FS8 depth stencil format.
you should check (among many things) it before feeding it into pparams:


HRESULT hr;
hr = g_p3DDevice->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
g_displayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24FS8);
if(FAILED(hr))
{
MessageBox(0, "ERROR: D3DFMT_D24FS8 unavilable", 0, 0);
DebugBreak();
return;
}


Share this post


Link to post
Share on other sites
and also you definitely shouldn't do this

m_iWidth=c_pPlatform->GetMainWindow()->m_iWidth;
m_iHeight=c_pPlatform->GetMainWindow()->m_iHeight;

the window can be any size, while there are certain available resolutions for device. Set back buffer sizes to what ...
g_p3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &g_displayMode);...
tells you, or set them to 0 if you run in windowed mode.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!