Archived

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

directdraw surface forecolor problem

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

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites