Jump to content
  • Advertisement


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


How to stop dx method from crashing?

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

ive got a directx font class that ive made, used to create font types.
	class Font {
		LPD3DXFONT lp_Font;

		Font(char font[], int size, int weight,bool underline, bool italic)
			HDC hDC= GetDC( NULL );
			int nHeight= -( MulDiv( size, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );
			ReleaseDC( NULL, hDC );					
			HFONT hFont = CreateFont(nHeight, 0, 0, 0, weight, italic, underline, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font );
			D3DXCreateFont(lp_Device , hFont, &lp_Font);
			DeleteObject( hFont );	
			if (lp_Font!=NULL)
the problem is when im using it like so:
Font fntNormal;
	fntNormal=  Font("Arial", 12, 300, false, false);
	return 0;

The problem is the Font("Arial... bit makes it create a new instance and deletes it while fntNormal is still using it causing it to crash...getting access violation error I dont want to use pointers as i dont want to have to bother deleting them, and i dont really want to have a method in there eg create() as this will be the style for alot of other classes that i may use. So i dont want to have to know functions etc. Are there any other ways of getting this working? Thanks,

Share this post

Link to post
Share on other sites
my first guess would be that you have to declare a copy-constructor in the class:

class Font
Font( const Font& F )
// do a deep copy, create new lp_Font object
// and set it''s properties to the ones F had.

By default, the copy-constructor doesn''t do a deep copy, but only copies the variables or pointer addresses.

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!