Jump to content
  • Advertisement

Archived

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

Fresh

Is there a memory/object leak in this:

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

  
void
CDD::LineGDI(LPDIRECTDRAWSURFACE7 lpDDSTarget, int x1, int y1, int x2, int y2, int color)
{
	HDC hdc;
	HPEN pen = CreatePen(PS_SOLID, 0, color);

	lpDDSTarget->GetDC(&hdc);
	SelectObject(hdc, pen);
	MoveToEx(hdc, x1, y1, NULL);
	LineTo(hdc, x2, y2);
	SelectObject(hdc, NULL);
	lpDDSTarget->ReleaseDC(hdc);
	DeleteObject(pen);
}
  
r. "The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."

Share this post


Link to post
Share on other sites
Advertisement

  
CDD::LineGDI(LPDIRECTDRAWSURFACE7 lpDDSTarget, int x1, int y1, int x2, int y2, int color)
{
HDC hdc;
HPEN pen = CreatePen(PS_SOLID, 0, color);
lpDDSTarget->GetDC(&hdc);
HPEN hOldPen = SelectObject(hdc, pen); //****

MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
SelectObject(hdc, hOldPen); //****

lpDDSTarget->ReleaseDC(hdc);
DeleteObject(pen);
}


A quote from the docs for SelectObject:
quote:

This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object.




--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

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!