Archived

This topic is now archived and is closed to further replies.

GekkoCube

d3dx texture drawing crashes system!

Recommended Posts

this is how i set a texture, which was initialized to null prior to this call: D3DXCreateTextureFromFile( g_pd3dDevice, ptexture, &m_Texture ); I do check for errors, and it returns successfully. problem is when i use SetTexture(0, m_Texture)...it crashes the system here. when i use SetTexture(0,NULL), it is ok. cant figure out what could be wrong. im thinking the texture was lost due to something sometime prior to the SetTexture call...?

Share this post


Link to post
Share on other sites
you know, i debugged it while watching the m_Texture.

When i load a texture m_Texture looks like it is loaded.
But when it comes time to SetTexture, it appears that m_Texture is not valid.

I have not yet checked the HRESULT return value for it but will try that right away.

NOTE: m_Texture is defined as a private member of a class.
1) it is set to NULL in the constructor.
2) a texture is loaded in another function.
3) and SetTexture() and rendering are called in a draw function.

Share this post


Link to post
Share on other sites
ok, now im lost even more.
i checked the return value for SetTexture, and it returns D3D_OK.

HRESULT hr = g_pd3dDevice->SetTexture(0, m_Texture);

BTW, i should note that setting SetTexture(0,NULL) does not cause problems. and view the m_Texture with debugger reveals somethings like errors at location 0, 1, 2 (whatever that means).

this is fucntion that causes the problem, in which commenting out the node.Draw(0) will run ok, but leaving it in causes a crash.


void DrawLines()
{
D3DXMatrixIdentity(&m_World);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &m_World);

g_pd3dDevice->SetStreamSource( 0, m_pVB, m_SizeOfInfo );
g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX_UNTRANSFORMED1 );
g_pd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, m_Count );

// update and draw the nodes at the joint locations

HRESULT hr = g_pd3dDevice->SetTexture(0, m_Texture);
if ( hr == D3D_OK)
{
dbgprintf(("hr is valid\n"));
}

for (int i=0; i<m_VBLength; i++)
{
D3DXVECTOR3 v(m_vertices[i].x, m_vertices[i].y, m_vertices[i].z);
m_node.SetPos(v);
m_node.Render(0);
}

g_pd3dDevice->SetTexture(0, NULL);
//dbgprintf(("DrawLines ok\n"));

}

Share this post


Link to post
Share on other sites
You could be clobbering either the texture pointer, or the data the texture is pointing to.


When you call SetTexture(0,NULL), DX goes down one code path that clears the texture pointers.

When you can SetTexture(0, m_pTex), DX tries to access the texture, extracting width & height, texture format, location, etc.

If, for some reason, the value of m_pTex changes from your CreateTexture() call to the point where you use it, the pointer may still look 'valid' ie - not NULL, but it points to memory that isn't a representation of a texture. As a result, when DX goes to try to access the width & height information, it will get garbage data which might be what's causing DX to crash out on you.

Check that you don't have any array bounds overflows, or loading a texture into a pointer twice, and then releasing it once, or some such thing. That's my guess on what the problem is, without knowing any more.


[edited by - Sphet on September 1, 2003 2:24:34 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by GekkoCube
cool.

i do have my dx setup as a debug run.
how do i run in debug runtime?


In the windows system settings you find a link to a dx configuration-tool. Open the Direct3d-Tab and check the Radio-Button at debug-runtime. Then debug your Programm in VS (f5). Every output of the debug-runtime is then displayed in the output-window of VS.

Share this post


Link to post
Share on other sites
i dont believe this to be a problem,

but the LPDIRECT3DTEXTURE8 im using is a private member of a class. in its render function i call SetTexture.
between setteture(0,texture) and settexture(0,null) i call a render function that is of another object, also defined as a private member.

so basically i setup the texture in one class so i can use it to apply a texture for objects drawn in another class.

i dont think this is a problem, but who knows.?

Share this post


Link to post
Share on other sites
cool...we''re narrowing down the problem here!
after doing a runtime debug, i immediately got a error with trying to lock the vertex buffer which exceeded the buffers size. so i quickly fixed that.

now the only feedback im getting about the settexture() is the following:

Direct3D8: (ERROR) :Texture not created with this device. SetTexture failed.

im not seeing any though...right now im looking thru the source to see if im reloading it twice or anything like that.
i put print statements everywhere where things are created and destroyed. so far, everything looks fine.

Share this post


Link to post
Share on other sites
Hmm...after fixing my vertex buffer locking issue, the settexture now return an error. This is a good thing since we are now getting somewhere.

the dx sdk doc says settexture returns negative values for errors. this is the error i got:

FAILED: -2005530516

to which HRESULT does this correspond to?

Share this post


Link to post
Share on other sites
hmm..after further investigation i was copying my vertex buffer with an incorrect size. this solved virtually everything i was referring to before!

thanks for all the helps.
thanks.
thread closed.

Share this post


Link to post
Share on other sites