Access violation reading location
Hi all,
I had my code in a reasonable condition when, what seemed out of nowhere I got the following error;
First-chance exception at 0x0047e917 in example1.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
Unhandled exception at 0x0047e917 in example1.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd.
The program '[1000] example1.exe: Native' has exited with code 0 (0x0).
The problem appears to be with the following code;
sprite_handler->Draw(
car_image,
NULL,
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));
Actually it points to the last line, D3DCOLOR_XRGB(255,255,255));
I'm making a game with C++ and DirectX 9.0 BTW. I haven't touched this code in ages and from what I see there isn't anything wrong with it.
So far all I've done is try rebuild the project without sucess.
Any thoughts, please!!!
0x0047e917 - this is the address of the faulting instruction. It's somewhere in your code.
0xcdcdcdcd - this is the address of the location to be read. Trying to read addresses above 0x80000000 will always throw. This is a debugging value anyway [1].
0xcdcdcdcd - this is the address of the location to be read. Trying to read addresses above 0x80000000 will always throw. This is a debugging value anyway [1].
Quote:
0xCDCDCDCD is a debugging value that comes from the bowels of the C runtime library. When you allocate a block of memory in a debug build, it's initialized to this spurious value in the hope of catching bugs. 0xCDCDCDCD is non-NULL and is never a valid memory pointer.
...
Sounds like a pointer error. Try checking that the sprite_handler and car_image are valid pointers. Also, make sure you reset any pointers to NULL when you create them (or in the constructor).
Allan
Allan
I tried setting all the pointers to NULL in the constructor but that made the images not appear! The background did however and I was able to move around as if the car was there.
I never set them to NULL in the constructor before and worked without it.
sprite_handler and car_image seem to be valid pointers, they are declared in the header file as follows;
LPDIRECT3DTEXTURE9 car_image;
LPD3DXSPRITE sprite_handler;
Thanks for the quick responce!
I never set them to NULL in the constructor before and worked without it.
sprite_handler and car_image seem to be valid pointers, they are declared in the header file as follows;
LPDIRECT3DTEXTURE9 car_image;
LPD3DXSPRITE sprite_handler;
Thanks for the quick responce!
I just noticed too, in reference to 0x0047e917, that the call stack says "d3dx9d.dll!0047e917"
Is this important? (Potential stupid question, i know)
Is this important? (Potential stupid question, i know)
sprite_handler is an invalid pointer. It's declared, yes. But it's not created. You need to use D3DXCreateSprite to create it.
The reason the compiler breaks on the last line is that it's only one function call. So it breaks at the end of it.
The reason the compiler breaks on the last line is that it's only one function call. So it breaks at the end of it.
I do have that code;
hr = D3DXCreateSprite(pd3dDevice9, &sprite_handler);
if (hr != D3D_OK)
return 0;
So thats not the problem.
There are also lots of function calls for each of the sprites. If I were to comment out the function call for car_image it would find the same problem with the next sprite, which would barrier (declared the same way as car_image)
hr = D3DXCreateSprite(pd3dDevice9, &sprite_handler);
if (hr != D3D_OK)
return 0;
So thats not the problem.
There are also lots of function calls for each of the sprites. If I were to comment out the function call for car_image it would find the same problem with the next sprite, which would barrier (declared the same way as car_image)
Use the debugger's variable watch window to look at the value of sprite_handler when you get the access violation. I'm still betting it's 0xcdcdcdcd. What happens if you put the call to D3DXCreateSprite just before the Draw() call? Does it work then?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement