ClearWorld and Images

Blitz3D Forums/Blitz3D Programming/ClearWorld and Images

KuRiX(Posted 2005) [#1]
In the manual i read that ClearWorld clears entities, textures and brushes.

What about images? are they cleared or do i need to freeimage one by one?


RGR(Posted 2005) [#2]
Its easy to find out
Load one of your images, make a ClearWorld and then display your image - if its still there :-) you'll see it - otherwise an error message will appear
Blitz is a TryAndError-Language... maybe that's why we still stick to it ... keeps your brain cells working


KuRiX(Posted 2005) [#3]
Ok, Tested. ClearWorld doesn't clear the images. So, any method to clear them all without managing every single handle?

P.D: Changing Resolution to the same value it has, deletes the images...


RGR(Posted 2005) [#4]
If you have loaded to many and need space then you must free images handle by handle - if this is no problem it is done by blitz when the program ends.

What do you mean "Changing Resolution to the same value... ?
A line of code added could explain what you meant.


PowerPC603(Posted 2005) [#5]
I think he means that, when using a screensize of 640x480, using the Graphics command again with the same resolution.
This will unload all pictures, but the handles to them still exist.
When you try to display them afterwards, you'll get an error.

You could use an array if you have lots of images.
Then just loop through them:
Graphics 800, 600, 0, 2

Dim ImageArray(100)

ImageArray(1) = LoadImage("c:\test1.jpg")
ImageArray(2) = LoadImage("c:\Test2.jpg")

DrawImage ImageArray(1), 10, 10
DrawImage ImageArray(2), 200, 200

WaitKey()

For i = 0 To 99
	If ImageArray(i) Then ; Check to see if there was an image loaded or not
		FreeImage ImageArray(i)
	EndIf
Next

DrawImage ImageArray(1), 10, 10 ; Error, image has been freed

WaitKey()



KuRiX(Posted 2005) [#6]
Well. Changing the resolution to the same value means that if you REset the resolution again to the same value it has now, you keep the resolution but clears all the images (exactly what PowerPc Says). The problem is this produces a screen flickering (to change the resolution).

The best way is what PowerPc Says. In fact is what i was doing. Any way you need to set ImageArray(i) = 0 after every freeimage, cause freeimage does not set it for you.

thanks all!


Rook Zimbabwe(Posted 2005) [#7]
PowerPC has a great piece of code there... I just FreeImage #imagehandle# because I know what images I called but I really dont use more than 10 images as buttons for my GUI...

Don't forget to free the sounds as well if you don't need them!

RZ


RGR(Posted 2005) [#8]
@KuRiX - I see what you mean - but I did never expect someone would use Graphics3D twice in a program just to delete Images... that's weird - especially if you consider its quite certain that this is only a sideeffect. The memory is not really freed - or is it?
I use whenever I load more than 2 or 3 images a list of types to store the handles (and sizes if needed) and run through the list to free them.


KuRiX(Posted 2005) [#9]
Someone told me long time ago that Graphics3D frees the memory too... at least the texture memory.

Of course i don't want to use graphics3d again and again to free the images.

It is only that think of this code:

im1 = loadimage("mydog.bmp")
im1 = loadimage("mycat.jpg")

In this case, how can i free the first image memory?. Perhaps ClearWorld should have an option to delete the images, sounds, etc... it would be awesome!


Rook Zimbabwe(Posted 2005) [#10]
BlitzMAX is supposed to have better garbage collection.


Ross C(Posted 2005) [#11]
Load all your images into a type collection. Freeing them all is a simple case of looping through them all :o)