0
votes

I'm creating D3D cursor, so first I made Surface & Texture. and doing this, I met error on GetSurfaceLevel() Function.

Unhandled exception at 0x5B494B11 0xC0000005: Access violation reading location 0x00000000.

code:

D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );

g_D3dDevice->ShowCursor( TRUE );

What should I do?

1

1 Answers

2
votes
Unhandled exception at 0x5B494B11 0xC0000005: Access violation reading location 0x00000000.

This kind of error was caused by dereference a NULL pointer, check whether you have create the texture successfully. Make sure g_cursortex not NULL before calling g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );

HRESULT hr = D3DXCreateTextureFromFile( g_D3dDevice, L"cursor1.bmp", &g_cursortex );
if (SUCCEEDED(hr))
{
    g_cursortex->GetSurfaceLevel( 0, &g_surfcursor );
    g_D3dDevice->SetCursorProperties( 0, 0, g_surfcursor );
}