简体   繁体   中英

D3D - GetSurfaceLevel unhandled exception

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM