Just
Sep 30th, 2000, 08:38 AM
Hi all,
I'm currently writing a program for my university Graphics unit, and I would very much appreciate some help (it's due in just a few days!) In this program, I use the API function CreateSolidBrush to choose a colour before calling the API procedure Polygon to draw a polygon to the screen.
The problem, however, is that continually calling CreateSolidBrush causes my computer to run out of memory. Every single polygon in my scene is a different colour (due to lighting) and so I need to create a different brush for every single polygon.
After I draw the current polygon, I call the API procedure DeleteObject to delete the brush I just used. I definitely call DeleteObject as many times as I call CreateSolidBrush. Despite this, my computer very, very quickly runs out memory (causing Windows to do all sorts of weird things, such as not even draw its icons correctly, to come up with system errors, etc).
Does anyone have any idea why I have this memory leak? If no, does anyone know of a way to modify a brush to change its colour without having to create a new brush? Here's a few lines of code from my program, in case it helps (Brush is of type Long, I and Count are Integers):
For I = 1 To Count ' Count is the number of polygons
Brush = CreateSolidBrush(Polygons(I).Colour) ' Create a "brush"
SelectObject frmGraphics.hdc, Brush ' Select that brush
Polygon frmGraphics.hdc, Polygons(I).Screen(1), UBound(Polygons(I).Screen) ' Draw the polygon
DeleteObject Brush ' Delete the brush
Next I
Thanks a-plenty,
Justin
I'm currently writing a program for my university Graphics unit, and I would very much appreciate some help (it's due in just a few days!) In this program, I use the API function CreateSolidBrush to choose a colour before calling the API procedure Polygon to draw a polygon to the screen.
The problem, however, is that continually calling CreateSolidBrush causes my computer to run out of memory. Every single polygon in my scene is a different colour (due to lighting) and so I need to create a different brush for every single polygon.
After I draw the current polygon, I call the API procedure DeleteObject to delete the brush I just used. I definitely call DeleteObject as many times as I call CreateSolidBrush. Despite this, my computer very, very quickly runs out memory (causing Windows to do all sorts of weird things, such as not even draw its icons correctly, to come up with system errors, etc).
Does anyone have any idea why I have this memory leak? If no, does anyone know of a way to modify a brush to change its colour without having to create a new brush? Here's a few lines of code from my program, in case it helps (Brush is of type Long, I and Count are Integers):
For I = 1 To Count ' Count is the number of polygons
Brush = CreateSolidBrush(Polygons(I).Colour) ' Create a "brush"
SelectObject frmGraphics.hdc, Brush ' Select that brush
Polygon frmGraphics.hdc, Polygons(I).Screen(1), UBound(Polygons(I).Screen) ' Draw the polygon
DeleteObject Brush ' Delete the brush
Next I
Thanks a-plenty,
Justin