d3dx texture drawing crashes system!

Started by
13 comments, last by GekkoCube 20 years, 7 months ago
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...?
Advertisement
Did you checked the returned HRESULT of SetTexture? Maybe the device pointer isn''t valid!?
- n/a -
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.

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"));	}
Have you used the DX-DebugRuntime for debugging your Programm? Maybe the DebugRuntime offers you some more informations about possible problems with the texture-file.
- n/a -
cool.

i do have my dx setup as a debug run.
how do i run in debug runtime?
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]
okay, thanks.
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.
- n/a -
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.?

This topic is closed to new replies.

Advertisement