Skip to main content
gamedev.net
🔒 Locked

GDI Problem

Started by azurianarcher 8 replies 1.2k views
Original Post
azurianarcher
azurianarcher
Im writing a remake of the mathematical game Life as an activex control. Im using GDI to do the drawing. However, after a few iterations, GDI cant handle the drawing and sorta whites out. Is there any way to fix this? if not what are my alternatves to GDI? i can post source code and details if neccesary. thanks, ~Amx
Zipster
Zipster
Are you remembered to release your device contexts? If you get too many without releasing them, GDI just kinda poops out on you

[edited by - Zipster on April 19, 2004 3:52:59 PM]
azurianarcher
azurianarcher
I think i did, does MFC do that automatically when the class'' descrutor is called?

~Amx
CodeMunkie
CodeMunkie
A lot of the GDI functions that aquire or create resources have a release counterpart. If you don''t call the release for each resource you have aquired or created, you will eventually run out of those resources. A common mistake is to call GetDC every frame and then not call ReleaseDC at the end of that frame. After maybe 100 frames or so of GetDC with no ReleaseDC you will run out of resources. Of course a lot of it depends on what OS you are using and your machine specs. It might be good to let people see your render code that way we can point out potential trouble spots.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
azurianarcher
azurianarcher
sure, heres the OnDraw method of my control:

void CLifeCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CMemDC dc(pdc,&rcBounds);

dc->Rectangle(&rcBounds);
for(int x = 0; x < GRIDSIZE; x++)
{
for(int y = 0; y < GRIDSIZE; y++)
{
dc->Rectangle(&grid[x][y]);
if(gridOn[x][y])
{
CBrush *oldBrush = dc->SelectObject(new CBrush((COLORREF)0x00FF0000));
dc->Rectangle(&grid[x][y]);
dc->SelectObject(oldBrush);
}
}
}
}

The way i set it up, this is the only place drawing occurs.

~Amx



[edited by - azurianarcher on April 19, 2004 4:35:30 PM]
LordElectro
LordElectro
I''m not familiar with MFC but new CBrush((COLORREF)0x00FF0000));
Aren''t you leaking an object there?
BetaShare - Run Your Beta Right!
try_catch_this
try_catch_this
clicky
http://www.freewebs.com/try_catch_this/organisims.zip

I made this for an assignment when I first learned win32. It was basically the first win32 app I made other than the basic frame.

I didnt have any problems with gdi maxing out. You need to check your code again.

[edit] for some reason direct link wouldnt work, so I posted the url



gdipong

oglpong



[edited by - try_catch_this on April 19, 2004 4:46:04 PM]
Zipster
Zipster
quote:
Original post by LordElectro
I''m not familiar with MFC but new CBrush((COLORREF)0x00FF0000));
Aren''t you leaking an object there?

Yeah, it''s a leak. That''s not good.
azurianarcher
azurianarcher
So i need to store it someplace then delete it, ill try that an get back, thx a lot everyone

~Amx
azurianarcher
azurianarcher
that did it, thx a lot everyone, that was just a memory leak too rite? i cant beleive i didnt catch that

~Amx

Topic Locked

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

Sign in to reply to this topic.