🔒 Locked
GDI Problem
Advertisement
Original Post
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
I think i did, does MFC do that automatically when the class'' descrutor is called?
~Amx
~Amx
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.
sure, heres the OnDraw method of my control:
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]
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]
I''m not familiar with MFC but new CBrush((COLORREF)0x00FF0000));
Aren''t you leaking an object there?
Aren''t you leaking an object there?
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]
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]
So i need to store it someplace then delete it, ill try that an get back, thx a lot everyone
~Amx
~Amx
that did it, thx a lot everyone, that was just a memory leak too rite? i cant beleive i didnt catch that
~Amx
~Amx
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement