Sign in to follow this  

DrawIndexedPrimitive crashes! Help brainstorm reasons why.

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

So. I have this here 3D Engine I've written in C++ in Visual C++ 2005 Express Edition. It's running from a DLL which works fine and great. I have a small test program that loads resources, creates objects, and has a very simple render loop. ( just while(true){ Render(); Present(); } ) All that is great. However, it crashes in my Render() function. Using calls to MessageBox() as checkpoints, I have pinpointed the error down to DrawIndexedPrimitive(), which renders the three test rectangles I have in the scene. Well, not at the same time of course. It loops through the objects I have buffered up for rendering by setting the shader constants, changing the vertex and index buffers (if necessary), and then calling DrawIndexedPrimitive for it ( or just DrawPrimitive, if it's not using an index buffer. My rectangles are, though. ) The crash itself happens within DrawIndexedPrimitive. It doesn't return anything - the crash isn't my code directly messing up. The message looks like this: First-chance exception at 0x0159c6c9 in LXTest1.exe: 0xC0000005: Access violation reading location 0x023cf674. Unhandled exception at 0x0159c6c9 in LXTest1.exe: 0xC0000005: Access violation reading location 0x023cf674. So it's reading memory that is out of bounds. Some pointer it's accessing internally is set to 0x0159c6c9, which is not a valid piece of memory (I believe.) Naturally, there is something I am doing (or not doing!) that is making it do this. I've been Google searching and Gamedev searching for all the different ways DrawIndexedPrimitive could crash. I've been going through the possibilities, but without much luck: - I am indeed using the most recent, August 2006 DirectX SDK. I tried grabbing that before making this post, to see if it would work - it didn't help. I was using the April 2006 SDK before, as I didn't get around to getting the new one. - I checked to see if my index and vertex buffers were valid. If they were big enough to hold all the primitives I wanted to draw, if they were being locked and filled okay. I checked, and actually ended up fixing a few things. But in their fixed state, I still get this crash. - I made sure the vertex and pixel shaders were set alright. I read one page where a guy got a crash on DrawIndexedPrimitive, and it turned out he didn't have any vertex shader set. Not the case - I can call GetVertexShader on my D3D Device, and it's what it should be. - I checked return values of a bunch of things, namely SetStreamSource, SetIndices, BeginScene, SetVertexShader, SetPixelShader, etc. They all return successful. - I set the DirectX runtime to the debug runtime. Set the slider to maximum debug information. The worst there is are some redundant SetRenderStates, which shouldn't be a big deal...right? Besides that, I get no debug information regarding my error. - I compiled with D3D_DEBUG_INFO in Projects->Properties->Configuation Properties->C/C++->Preprocessor. It successfully enables the debug info (I guess), but it doesn't tell me anything new. - I'm not drawing a whole lot of triangles here. It's a rectangle, so it's like 12 triangles total. I also confirmed that 12 is indeed getting passed to DrawIndexedPrimitive in the PrimitiveCount parameter I can post code you might want to examine for correctness at whatever steps along the way you might think an error could be happening. Or post whatever other information you think is relevant. Any help, suggestions on what important elements to check, check and recheck are executing correctly, or conjecture as to what could be the problem would be great.

Share this post


Link to post
Share on other sites
I *think* 0x0159c6c9 is the location of the instruction causing the code to crash, and 0x023cf674 is the memory location being read.

what's the stride on your vertex format? Is that being set correctly? Have you tried using the fixed function pipeline instead of your shader? I'm probably not asking good questions here because I've never used programmable shaders.

you probably checked already, but are you using triangle lists when your data is actually for triangle strips? Lists will need more vertices then strips.

Share this post


Link to post
Share on other sites
Just guessing randomly: The settings you gave it might make it try to read past the end of your vertex buffer.

Exception addresses are always code. The first one (0x0159C6C9) looks like a DLL to me (the EXE is usually loaded down at 0x00400000 if you built it with Visual Studio). 0x023CF674 is probably nearby (but slightly outside -- causing the crash) heap memory associated with one of the DLLs that's loaded (probably DirectX).

Are you good with a hexeditor? Make sure you have visual studio's debugger attached when you run. When you see the crash, go to the memory address that it lists in the crash message using the "Memory" window (I'm not sure if Express has that) and back up a few bytes until the debugger finds valid memory to read (i.e. try to get inside whatever valid memory region is just before the bad address). Check the contents of that against what you fed into your vertex buffer or any other buffers that you used (I doubt it would crash like this on a texture resource...).

Share this post


Link to post
Share on other sites
Quote:
what's the stride on your vertex format? Is that being set correctly? Have you tried using the fixed function pipeline instead of your shader?
My vertex is an even 128 bytes. I'm creating the declaration successfully, and then setting it, so I think it's alright. I put some checks on the call to SetVertexDeclaration, but it returns successful.
Quote:
but are you using triangle lists when your data is actually for triangle strips? Lists will need more vertices then strips.
It's a triangle list, and I put in a check to make sure it is triangle list, and it successfully is triangle list. I 'check' this because the models I load from my format can choose whatever type they want :) Looks like it is set correctly, though.
Quote:
When you see the crash, go to the memory address that it lists in the crash message using the "Memory" window (I'm not sure if Express has that) and back up a few bytes until the debugger finds valid memory to read (i.e. try to get inside whatever valid memory region is just before the bad address).
It looks like it's just pointing out into the middle of nowhere, actually. I scroll up for a while and just get more ?'s.

Image hosted by ImageSocket.com

Share this post


Link to post
Share on other sites

This topic is 4088 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this