Unknown Error involving an Image

Blitz3D Forums/Blitz3D Beginners Area/Unknown Error involving an Image

OwlEpicurus(Posted 2009) [#1]
The game I am programming has a HUD in the upper left corner. The code to make it is:



Most of the time, there is no issue. However, after approximately 3000 iterations through the main loop (in which this function is called every time) an error message appears with the line

HUD = CreateImage(90,5*row)


highlighted. However, the error message consists of a title bar (app title is run time error) and a transparent box. What could the error be, and what could be causing it?


Matty(Posted 2009) [#2]
You are creating an image every frame, which takes up video memory, and you are not releasing it by freeing the image when you are done with it. Also, because it is using a local variable in that function for the image handle you are unable to access it after leaving the function.
Basically your filling up memory with an image that you lose the handle to as soon as you exit that function.

Perhaps a better way would be to create the image once outside of the function, and simply redraw to it as needed rather than create a new image every frame.

Also - you need to manage your handles better - to prevent memory leaks you need to keep a reference to the handle so that you can free it as needed.


OwlEpicurus(Posted 2009) [#3]
Thanks! I'm still new at this.