Jump to content
  • Advertisement

Archived

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

agent666

Possible Memory Leak (Need response fast!)

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

hi, i have this code, and the code gets called about 300 times a section to draw anything i pass to the function, but my worry is it''s creating a memory leak.
void DrawTextureBox(float Xpos, float Ypos, float width, float height, LPDIRECT3DTEXTURE8 g_texture, float MaxMagnify)
{
	HRESULT hr;

    g_d3d_device->SetTextureStageState(0,D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
    g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);	
    
	//This enables Alpha Blending
   g_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

   g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
   g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);

   g_d3d_device->SetTexture(0, g_texture);
	
	//top left of box
	g_square_vertices[0].color = 0xFFFFFFFF;
	g_square_vertices[0].x = Xpos;
	g_square_vertices[0].y = Ypos;
	g_square_vertices[0].z = 0.5f;
	g_square_vertices[0].rhw = 1.0f;
	g_square_vertices[0].tu = 0.0f;
	g_square_vertices[0].tv = 0.0f;

	//bottom left of box
	g_square_vertices[1].color = 0xFFFFFFFF;
	g_square_vertices[1].x = Xpos;
	g_square_vertices[1].y = Ypos + height;
	g_square_vertices[1].z = 0.5f;
	g_square_vertices[1].rhw = 1.0f;
	g_square_vertices[1].tu = 0.0f;
	g_square_vertices[1].tv = MaxMagnify;

	//top right of box
	g_square_vertices[2].color = 0xFFFFFFFF;
	g_square_vertices[2].x = Xpos + width;
	g_square_vertices[2].y = Ypos;
	g_square_vertices[2].z = 0.5f;
	g_square_vertices[2].rhw = 1.0f;
	g_square_vertices[2].tu = MaxMagnify;
	g_square_vertices[2].tv = 0.0f;

	//bottom right of box
	g_square_vertices[3].color = 0xFFFFFFFF;
	g_square_vertices[3].x = Xpos + width;
	g_square_vertices[3].y = Ypos + height;
	g_square_vertices[3].z = 0.5f;
	g_square_vertices[3].rhw = 1.0f;
	g_square_vertices[3].tu = MaxMagnify;
	g_square_vertices[3].tv = MaxMagnify;
	
	hr=g_square->Lock(0, 0, &Temp_Vertexbuff, 0);

	memcpy(Temp_Vertexbuff, g_square_vertices, sizeof(g_square_vertices));

	hr=g_square->Unlock();

	g_d3d_device->BeginScene();

	g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	g_d3d_device->EndScene();

 
It''s my belief that when you do a lock, it copies the whole vertex information rather than remebering the pointer to that data. so by doing a lock, it''s creating lots of copies in memory without getting rid of it. Am i right????? And if i''m right, how do i free the data loaded through the lock???

Share this post


Link to post
Share on other sites
Advertisement
By calling unlock. As long as you have an unlock for every lock, you''ll be fine. As long as you have a Release for every COM object created, you''ll be fine too.

Chris

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!