directdraw surface forecolor problem

Started by
4 comments, last by karlb 20 years, 1 month ago
I have an application using direct draw. The following code appears in it. backBuffer.ForeColor = System.Drawing.Color.White; where backBuffer is a DirectX Surface After this line executes several hundred times I get this error. Value cannot be null. at Microsoft.DirectX.DirectDraw.Surface.set_ForeColor(Color value); Can anyone explain to me what is happening? Also, if I avoid this problem by only setting the forecolor once at the very beginning of my program. At a random time part way through everything drawn in the forecolor no longer is visible. Thanks
Advertisement
Sounds like backBuffer is null? try adding this (VC#):

using System.Windows.Forms;

if (backBuffer == null)
then MessageBox.Show("This ism't cool.")
else backBuffer.ForColor = System.Drawing.Color.White;

I am having a similar problem to yours; my sprites suddenly dissapear all of a sudden and I really can't find whats happening to them.


[edited by - sanity on March 24, 2004 4:01:05 PM]
sanity,
I tried your suggestion. The backBuffer is never null. Any other ideas?

Thank
I think you may be having the same problem that I am having, I seem to have found the solution in another post(mid way down this http://www.gamedev.net/community/forums/topic.asp?topic_id=140637) for me the only solution is a rewrite of my Graphical classes (which will be a pain) but I am going to do it no matter how long it takes me!
Thanks for your response Sanity. I check out that link, but it is not the same problem I am having. I am only loading each of my surfaces once. Best of luck with your code.

Anyone else have suggestions.
I have found the solution to my problem. The debugger was pointing me the wrong way the whole time. The problem was with handles.

On my screen I was drawing text. I called the following to change fonts several times during each paint.

Font drawFont = new Font("Impact", 16);
backBuffer.FontHandle = drawFont.ToHfont();

I think that I was using up the font handles faster than the garbage collector could free them. I don''t know why the debugger never pointed a finger this way.

The lesson, you still have to watch out for the same problems with handles and resources in managed code that you had to with good old win32.

This topic is closed to new replies.

Advertisement