Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

System.Drawing.Font fntT = new System.Drawing.Font("Courier New",10);

surPrint.FontHandle = fntT.ToHfont();

surPrint.ForeColor = Color.White;

 

Hi, the above code is exactly what i use to set the font handle of the surface. This code exsists in the main loop, so for every frame this is executes.

When i run the program it works fine for about a minute or two, until an exception occurs:

 

An unhandled exception of type 'System.ArgumentNullException' occurred in microsoft.directx.directdraw.dll

 

Additional information: Value cannot be null.

 

This is very annoying. Nothing changes in the loop... the same code is executed. As I said before the code works for about 2 minutes then throws this exception.

 

I commented out the lines dealing with the font handle

System.Drawing.Font fntT = new System.Drawing.Font("Courier New",10);

surPrint.FontHandle = fntT.ToHfont();

 

And it runs fine without throwing any exceptions at any time.

So I'm guessing it has something to do with the font handle.

But it works fine for 2 mins :confused:.

 

Btw, because of what I have planned, I need to set the font handle every time it loops. So setting it before the loop begins is not an option for me. I hope this is not an internal error that is out of my reach, that would suck.

 

Any ideas / suggestions

thanx in advanced.

  • 2 years later...
Posted

This is a memory leak. A good fix would be to set this..

 

(My syntax my be wrong im a vb programmer..)

 

//Before your loop..

ptr as IntPtr = fntT.ToHfont();

 

//In your loop

System.Drawing.Font fntT = new System.Drawing.Font("Courier New",10);

surPrint.FontHandle = ptr

surPrint.ForeColor = Color.White;

 

//After your loop

ptr = nothing;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...