Jump to content
  • Advertisement


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


odd exception errors in D3D9

This topic is 5766 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''m having a rather odd problem with DirectX9 / C++.Net - I keep getting an exception from a piece of code and I cant find out how/why! I''ve done my utmost best to debug it - but even VStudio.Net isn''t being that helpful - the exception ("user breakpoint") breaks straight to dissasembly and the call stack just has the current (error) line and a previous line in dissasembly... I cant work out which line in my actual source code generates the error. However, by commenting out diff. lines I can find out roughly whats wrong. So I stick it in a try...catch block (to stop the unhandled exception), and it''s still thrown!! I dont get that! Here''s my code:
  try {
		LPRECT x = new RECT;
		x->top = 5;
		x->left = 5;
		x->bottom = 20;
		x->right = 200;
		char *pMsg = "blah";
		//pMsg = new char;

		//if (fCurrFPS < 10)

		//	fCurrFPS = -3.14159;

		//sprintf( pMsg, "Current Frame Rate: %d", (int)fCurrFPS );

		lpFont->DrawTextA(pMsg,-1, x, DT_TOP|DT_LEFT, D3DCOLOR_XRGB(255,0,0) );
		//delete pMsg;

	} catch ( ... ) {
		MessageBox(NULL, "EXCEPTION CAUGHT!!!!","Error",MB_OK);
Basically, I''m trying to get D3D9 to draw some text to the screen including the frame rate info. i specifically DONT want to use the SDK frameworks, hence I''m using my own code drawing text works fine - the fonts exist okay, I can replace param-1 in the DrawTextA() line above with "Hello" and it''ll print just fine. any hints!?! cheers Jack

Share this post

Link to post
Share on other sites
oh, one more thing...

the unknown exception doesn''t appear for a good 20-30 seconds into execution!

which means the above code has to tick-over 1500+ times before it causes an error!


Share this post

Link to post
Share on other sites
There are some issues with your code, but they''re C++ issues, not DirectX ones.

You dynamically allocate a RECT each time through your loop, but never seem to free it. Eventually it will fail and you''ll be dereferencing random memory.

Similarly the pMsg code that''s commented out, dynamically allocates a single char, then copies a long string over top (which trashes memory since your buffer is 1 char long).

At the top of your function, declare this:
char pMsg[80];

Then in your code:

x.top = 5;
x.left = 5;
x.bottom = 20;
x.right = 200;
sprintf( &pMsg, "Current Frame Rate: %d", (int)fCurrFPS);
lpFont->DrawTextA(&pMsg,-1, &x, DT_TOP|DT_LEFT, D3DCOLOR_XRGB(255,0,0) );

Stay Casual,

Drunken Hyena

Share this post

Link to post
Share on other sites
cheers, thought it might be something like that... it just really stumped me WHY i couldn''t trace the error any ideas on that?

the final code I had to use was:

RECT rcText;
char *pMsg = new char[100];

rcText.top = 5;
rcText.left = 5;
rcText.bottom = 20;
rcText.right = 200;

sprintf( pMsg, "Current Frame Rate: %d", (int)fCurrFPS );
lpFont->DrawTextA(pMsg,-1, &rcText, DT_TOP|DT_LEFT, D3DCOLOR_XRGB(255,0,0));
delete pMsg;

slightly different, but your code gave clashes with sprintf().


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!