Skip to main content
gamedev.net
🔒 Locked

Device Context problem

Started by IceCoder 3 replies 950+ views
Original Post
IceCoder
IceCoder
Hello everyone, I was coding as I usually do, and someone calls me at phone. I talked for about 5 minutes, and as I finished I saw my game crashed. So I investigate, and found that the problem is that after a certain period of time, the DC cannot be created :/ Do you know anything about? I'm using DirectDraw (please don't tell me it's old, I know it myself..) for managed. My DX version is 9.0c, and I use C# .NET EDIT: oh I forgot! The error message is the following: "Cannot create device context". I wrote it..even if it was evident itself...
Matias Goldberg
Matias Goldberg
You're using C#; so I don't know, but in C/C++ this usually means:

1) Buffer overflow somewhere else (doesn't have to be directly related to the DC)
2) The DC is wrongly deleted. Thus after a creating certaing number of DCs, they start to refuse.
3) A parameter is somehow being overwritten, surely not in the first creation.

Your app will probably take less to crash in win9x, you may find interesting to test it (Win9x sucks when dealing DCs badly allocated)

Hope it helps
Dark Sylinc
IceCoder
IceCoder
As I look at my code I cannot see any of these problems...

mhhh well.. it may be for this?

public static class EntryPoint    {        [STAThread]        static void Main(string[] args)        {            WndMain wndMain = new WndMain();            wndMain.Show();            while (wndMain.Created)            {                wndMain.Draw();                Application.DoEvents();            }        }    }


As you can see, I create the window but I do not override the OnPaint() function, I draw all the stuff by calling my "public void Draw()" from Main()
and then I call the DoEvents() to prevent crashing.

The other way I know is using the following code from the inside of the window class:
protected override OnPaint(object sender, EventArgs e){//...All the stuffInvalidate();}

but I didn't try this, because I believe they are about to be the same.

I have really no idea on what to do :/
Matias Goldberg
Matias Goldberg
Sorry, I can't help you much. But something tells me that's the 1% of your code. When I meant buffer overflow, I meant EVERYWHERE. Sometimes you have to look deep in your code. Also the best way would be intensive debugging

Dark Sylinc
IceCoder
IceCoder
Ok, I try debugging from the skin to the core... hope it works...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.