DirectX.DirectDraw.Surface.FontHandle help

Bhen Hur

Newcomer
Joined
Feb 28, 2004
Messages
2

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.
 
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;
 
Back
Top