Jump to content
  • Advertisement
Sign in to follow this  
Unliterate

What in the world.. (Direct X related)

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

Not a very well defined topic header but the problem hasnt really well defined itself either.. here's the situation: I'm trying to render some polys to a screen using DX9 but I'm getting inconsitant and random memory read errors, sometimes (but rarely) none at ALL. I have a load vertices function:
void DISPLAY::LoadVertexData(D3DXVECTOR2 *coordinates,D3DCOLOR *colors,int number_of_coords)
{
	VOID* pVertices;
	if(FAILED(D3DVertexBuffer->Lock(0,0,(void**) &pVertices,D3DLOCK_DISCARD/*entire buffer is overwritten*/)))
	{
		MessageBox(window,"Failed to lock the vertex buffer!","Damn!",MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	int index=0;
	while(index<number_of_coords)
	{
		screen_vertices[index].x=coordinates[index].x;//coordinates[index].x;
		screen_vertices[index].y=coordinates[index].y;
		screen_vertices[index].z=0.5f;
		screen_vertices[index].rhw=1.0f;
		screen_vertices[index].color=colors[index];
		index++;
	}

	memcpy(pVertices,screen_vertices,sizeof(/*CUSTOM_VERTEX*/screen_vertices)/**number_of_coords*/);

	if(FAILED(D3DVertexBuffer->Unlock()))
		MessageBox(window,"Failed to unlock the vertex buffer!","Damn!",MB_ICONEXCLAMATION | MB_OK);
}


It's kind of messy because of all the debug stuff in there. when i comment the one call of this function out of the program I get no errors. Now what gets me is this: when I debug it line by line, the error is in the D3DSprite->Begin(); function, which if commented will result in errors that aparently occur in my keyboard input functions, and no matter how much I comment out, more errors will spontaniously generate. Now I do have one global pointer but it points to every single thing in the program, and I have a feeling this might be related to the problem but I know nothing of the stack and heap and what not. The problem may also be with the way I'm using arrays in that function (anything clearly wrong there?). Again, with nothing commented out, about 35% of the time the program will run fine until I close it(then errors), the rest of the time immidiatly generating memory read erros. Any ideas or insight would be greatly appreciated, Thanks.

Share this post


Link to post
Share on other sites
Advertisement
the error I'm getting pretty consistantly now is "the instruction at "blah" referenced by memory "0xcdcdcdcd". the memory could not be read."

Share this post


Link to post
Share on other sites
Does your device create successfully? Your vertex buffer? What parameters do you pass to create your vertex buffer? What parameters to you pass to the function you showed?

Share this post


Link to post
Share on other sites
Nothing is failing as far as I know.I pass two arrays declared as follows:
D3DXVECTOR2 vertices[1000];
and D3DCOLOR colors[1000];

in the function that calls loadvertices().

Share this post


Link to post
Share on other sites
heres the vertex buffer initialization function:

HRESULT DISPLAY::InitializeVertexEngine(int maximum_vertices)
{
tester=D3DRenderDevice->CreateVertexBuffer(
maximum_vertices*sizeof(CUSTOM_VERTEX),
0,
D3DFVF_XYZRHW|D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT,
&D3DVertexBuffer,
NULL);
if(FAILED(tester))
{
MessageBox(window,"Failed to initialize the vertex buffer!","Damn!",MB_ICONEXCLAMATION | MB_OK);
return tester;
}

return NULL;
}






edit: could the fact that I'm calling the loadverticedata() every frame be causing a problem I havn't thought of?

Share this post


Link to post
Share on other sites
There is a direct correlation to the time I wait befor running and the probability that it will run and it seems almost exclusively dependent on that correlation.

Share this post


Link to post
Share on other sites
No, but it will make it run ungodly slow. Never ever lock a vertex buffer every frame unless it is marked with D3DUSAGE_DYNAMIC.

What is maximum_vertices?

memcpy(pVertices,screen_vertices,sizeof(/*CUSTOM_VERTEX*/screen_vertices)

What is screen_vertices? You have so many variables that there is no way anyone can help without knowing what they are.

[edit] Ignore that. It sounds like you are running out of room on the stack. Instead of D3DXVECTOR2 vertices[1000], try D3DXVECTOR2* vertices = new D3DXVECTOR2[1000]. Of course, remember to do delete[] vertices when the program closes.

Share this post


Link to post
Share on other sites
Do you mean the exact values or what their purpose is? I think the purpose is clear and I dont think the exact value would be of much relavence but maybe I'm wrong.

ps. Never mind that statement I made between time and succesful run correlation, seems it was just a fluke. Also I forgot to mention on rare occasions the program will just close with no read error message at all.

Share this post


Link to post
Share on other sites
0xcdcdcdcd is a hint to the problem. Those values are what the debug runtime fills memory with when it allocates the memory. So the presence of 0xcdcdcdcd suggests you are attempting to use something that has been allocated but not initialized.

Share this post


Link to post
Share on other sites
god this sucks, how do i get the little window that shows you what variable has what value (and automatically put varibles in there, has the 'local' and 'auto' tab)when your debugging in VC++ 6

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!