ID3DXLine
I am trying to use this to draw lines on the screen but when the program quits it crashs something to do with the winheap. The problem seem to be with the array of D3DXVECTOR2 that is passed into the draw function. The line draws fine exept when quiting. It still has a problem quitting even with just the vertexlist declared in the header. It must be something to do with the way i have declared the array.
define in the class private section:-
LPD3DXLINE m_line;
D3DXVECTOR2 VertexList[2];
bool CGfxEntitySprite::Initialise(const char* textureFilename)
{
HRESULT hr = D3DXCreateLine(gD3dDevice, &m_line);
m_line->SetWidth(1);
VertexList[0] = D3DXVECTOR2(10,10);
VertexList[1] = D3DXVECTOR2(50,50);
return TRUE;
}
void CGfxEntitySprite::Render(const D3DXMATRIX &matWorld)
{
m_line->Begin();
m_line->Draw(VertexList, 2, D3DCOLOR_XRGB(0,255,255));//Render to screen
m_line->End();
}
[Edited by - jammy5202 on April 23, 2006 4:45:46 AM]
It works fine with the declaring D3DXVECTOR3 VertexList[2] it is ok when i fill the first element in the array as soon as i enter anything in the second element it crashs on exit.
Quote:Original post by jammy5202
It works fine with the declaring D3DXVECTOR3 VertexList[2] it is ok when i fill the first element in the array as soon as i enter anything in the second element it crashs on exit.
This sounds like you are trashing the stack at some point. Are you running this in debug mode? If so, you should get some error dialog from the runtime telling you about it.
What can cause things like this? If you overwrite the bounds of an array, ZeroMemory()'ing over other memory, ect. These things can be hard to pick up sometimes.
There is nothing wrong with that code. I am doing almost the exact same thing to use ID3DXLine to draw a square on the screen:
private:
D3DXVECTOR2 mLineVerts[5];
ID3DXLine* mSelBox;
D3DCOLOR mLineColor;
Routine:
mLineColor = D3DCOLOR_XRGB(255, 255, 255);
mLineVerts[0] = D3DXVECTOR2((float)StartX, (float)StartY);
mLineVerts[1] = D3DXVECTOR2((float)EndX, (float)StartY);
mLineVerts[2] = D3DXVECTOR2((float)EndX, (float)EndY);
mLineVerts[3] = D3DXVECTOR2((float)StartX, (float)EndY);
mLineVerts[4] = mLineVerts[0];
V_RETURN( mSelBox->Begin() );
V_RETURN( mSelBox->Draw(mLineVerts, 5, mLineColor) );
V_RETURN( mSelBox->End() );
Are you saying that the error occurs when you exit the application (not when drawing the line as the program runs)? I have those pesky stack errors occur too when I exit my app. They are really hard to figure out. Do you have this set so you can catch memory leaks:
#include <crtdbg.h>
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
Also, for DirectX, switch to running with the debug version from the Control Panel.
private:
D3DXVECTOR2 mLineVerts[5];
ID3DXLine* mSelBox;
D3DCOLOR mLineColor;
Routine:
mLineColor = D3DCOLOR_XRGB(255, 255, 255);
mLineVerts[0] = D3DXVECTOR2((float)StartX, (float)StartY);
mLineVerts[1] = D3DXVECTOR2((float)EndX, (float)StartY);
mLineVerts[2] = D3DXVECTOR2((float)EndX, (float)EndY);
mLineVerts[3] = D3DXVECTOR2((float)StartX, (float)EndY);
mLineVerts[4] = mLineVerts[0];
V_RETURN( mSelBox->Begin() );
V_RETURN( mSelBox->Draw(mLineVerts, 5, mLineColor) );
V_RETURN( mSelBox->End() );
Are you saying that the error occurs when you exit the application (not when drawing the line as the program runs)? I have those pesky stack errors occur too when I exit my app. They are really hard to figure out. Do you have this set so you can catch memory leaks:
#include <crtdbg.h>
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
Also, for DirectX, switch to running with the debug version from the Control Panel.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement