FreeTexture() bug?

BlitzMax Forums/MiniB3D Module/FreeTexture() bug?

ima747(Posted 2009) [#1]
SuperStrict 

Import sidesign.minib3d

Graphics3D(640, 480, 32, 2)

Local count:Int

While Not KeyHit(KEY_Escape)
	Local tex:TTexture = 	CreateTexture(1024, 1024)'LoadTexture("test.jpg")
	FreeTexture(tex)
	
	GCCollect() ' Force a collect to make it easier to watch memory usage
	
	count = count + 1
	If(KeyHit(KEY_Space))
		Print count
	End If
Wend

watching memory usage of this test app it just goes up and up till it crashes. If you pause between the load and the free, and compare the memory usage to what it is after the free there is no change. basically freeing a texture doesn't release it. looking at TTexture.FreeTexture() it looks like I never unbinds the openGL texture...

just reinstalled 0.531 from the link in the sticky thread to ensure I wasn't using something broken and outdated.


ima747(Posted 2009) [#2]
Haven't tested enough to know if this is safe, but it works so far for my tests...

in TTexture.bmx change FreeTexture() to this
	Method FreeTexture()
	
		ListRemove(tex_list,Self)
		pixmap=Null
		cube_pixmap=Null
		
		For Local name = EachIn gltex
			glDeleteTextures 1, Varptr name
		Next
		gltex=Null
	
	End Method



Hujiklo(Posted 2010) [#3]
Well spotted! I just ran into that same problem now..not freeing textures actually saves ram! Weird...Your fix does the trick so far anyhow - so thanks!