Ever increasing VidMem usage

Blitz3D Forums/Blitz3D Programming/Ever increasing VidMem usage

HappyCat(Posted 2005) [#1]
I'm working out VidMem used simply as TotalVidMem() - AvailVidMem() and despite my best effort I can't stop it from always increasing. I'm freeing textures when they're not required and deleting entities when they're done with and as far as I can tell this is all happening correctly, but still the VidMem usage keeps going up. Is this normal with Blitz or am I missing something in my code?


skidracer(Posted 2005) [#2]
Check for missing UnlockBuffer commands.


HappyCat(Posted 2005) [#3]
Just checked - they're all Unlocked.


John Blackledge(Posted 2005) [#4]
Are you playing mpg or avi? There is a definite memory leak each time they loop - found by me, confirmed by a few people, unreplied to by Blitz Support.


Neochrome(Posted 2005) [#5]
Memory leak in movies??? Oh not good! i was going to use them!
Thanks for the heads up!

freetextures arn't enough, besure your freeing entities your not using too!

simply making the "pointer" setting that to 0 wont work.


HappyCat(Posted 2005) [#6]
Nope, no movie files. And I'm freeing entities too.

As it looks like this isn't normal then I presume I've just missed one somewhere. I'll have another look.


Uncle(Posted 2005) [#7]
Its a long shot, but I had a similar problem. I went through my code line by line, and still had the same problem. Then I updated my graphics card driver and since then no problems. Might be worth a shot?

Cheers,


Unc


HappyCat(Posted 2005) [#8]
It's happening on both my PCs and they both have different gfx cards (one is a Geforce 4, the other an Intel thingumywotsit).


John Blackledge(Posted 2005) [#9]
Memory leak in movies??? Oh not good! i was going to use them!

It all depends.
If it's a one-shot movie intro, that's probably ok, but if it loops then each time it will chew the memory equivalent roughly to the file size.
There appears to be no way to Free(the memory of) a movie.

It is quite a bind for me - I wanted movies on quads to simulate fire, water etc, not to mention TV. Now I've simply had to give up the idea, because even though it might take a few hours, eventually the user's machine/app will lock.


HappyCat(Posted 2005) [#10]
Okay, I think I've tracked it down. I'm using Syntax Error's Sprite Control code for pixel-perfect quad sprites. Sprites are loaded with the following Sprite Control function:
Function LoadImage3D(Filename$, Masked = True, texflags=4, Parent=-1, RetainAlpha=False)
	; Create quad mesh
	If Parent = -1 Parent = SpritePivot
	Local sprite=CreateMesh(Parent)
	Local s=CreateSurface(sprite)
	AddVertex s,0,0,0 ,0,0 : AddVertex s,2,0,0 , 1,0
	AddVertex s,0,-2,0 ,0,1 : AddVertex s,2,-2,0 , 1,1
	AddTriangle s,0,1,2 : AddTriangle s,3,2,1

	; transfer image into texture buffer (with alpha)
	Local tmpimage=LoadImage(Filename$)
	Local spritetexture=LoadTexture(Filename$,texflags)
	Local iw=ImageWidth(tmpimage) , ih=ImageHeight(tmpimage)
	Local tw=TextureWidth(spritetexture) , th=TextureHeight(spritetexture)

	If Not RetainAlpha Then
		
		If iw<>tw Or ih<>th
			ib=ImageBuffer(tmpimage)
			LockBuffer(ib)
			tb=TextureBuffer(spritetexture)
			LockBuffer(tb)
			For x=0 To iw-1
				For y=0 To ih-1
					rgbc=ReadPixelFast(x,y,ib) And $00ffffff
					If rgbc=((r Shl 16)+(g Shl 8)+b) And Masked  ; ALB - added And Masked 
						WritePixelFast x,y,($00000000),tb
					Else
						WritePixelFast x,y,(rgbc Or $ff000000),tb
					EndIf
				Next
			Next
			UnlockBuffer(ib)
			UnlockBuffer(tb)
		EndIf
	
	End If

	FreeImage tmpimage

	; Texture and resize sprite. Move handle to top/left
	ScaleTexture spritetexture,Float(tw)/Float(iw),Float(th)/Float(ih)
	EntityTexture sprite,spritetexture
	FreeTexture spritetexture

	EntityFX sprite,1+16
	EntityOrder sprite,-100
	ScaleEntity sprite,Float(iw)/2,Float(ih)/2,1
	PositionEntity sprite,-10000,-10000,0

	Return sprite

End Function


and free'd with
Function FreeImage3D(Sprite)
	Local brush = GetEntityBrush(Sprite)
	Local tex = GetBrushTexture(brush)
	If brush <> 0 FreeBrush brush
	If tex <> 0 FreeTexture tex
	If Sprite <> 0 FreeEntity Sprite
End Function

But FreeImage3D doesn't seem to actually release the Vid Mem, it just keeps going up. These Sprite Control functions are wrapped in my own code, but they don't really add much - eg. my delete sprite function is just:

Function DeleteSprite(Sprite.Sprite)

	If Sprite <> Null Then
		FreeImage3D(Sprite\SpriteControlID)
		Delete Sprite
	End If
	
End Function


Any ideas why FreeImage3D wouldn't be freeing up Vid Memory?


John Blackledge(Posted 2005) [#11]
It's a long shot but try freeing the texture before the brush.


HappyCat(Posted 2005) [#12]
Nah, didn't help. Is Blitz perhaps optimising things by just releasing textures but not actually freeing vid mem until it has to?


Shambler(Posted 2005) [#13]
According to the docs 'GetEntityBrush' and 'GetEntityTexture' actually create a new brush and a new texture so it would appear you aren't actually deleting the brush/texture applied to the sprite, only copies of them.

Is that what the docs mean?

If so you would have to store a handle to the actual texture+brush then delete them if no other sprites are using them.

If not then I'm just being very confused O.o


HappyCat(Posted 2005) [#14]
It appears that that might be the case. In which case, how do I actually delete the entity's texture?

What I'm finding confusing is that freeing the textures used by Planes and Terrains (which I use for backgrounds) works fine and frees up the vid mem they were using, but doing it for these quads doesn't seem to work.


BlitzSupport(Posted 2005) [#15]

There is a definite memory leak each time they loop - found by me, confirmed by a few people, unreplied to by Blitz Support


When was that?


Sledge(Posted 2005) [#16]

When was that?


http://www.blitzbasic.com/Community/posts.php?topic=46958&hl=leak

I gotta tell you, the number one thing putting me off BlitzMax is the way you keep "disappearing" continuing problems (FMOD anyone?) into the "Bug Bin", as if they were resolved. Doesn't exactly inspire confidence.


John Blackledge(Posted 2005) [#17]
Thanks, Sledge. I didn't want to say that, coz I love Blitz3D, Mark Sibly, and Blitz Support with a passion.

But this vid loop memory leak does make the use of video pretty well unusable, especially if you expect to leave it running in front of a customer (as in TV display, billboard display).


big10p(Posted 2005) [#18]
I didn't want to say that, coz I love Blitz3D, Mark Sibly, and Blitz Support with a passion.

You're their customer, not the other way around. If something doesn't work properly, you're allowed to complain...






...and they'll duly ignore you completely. :)


Hotcakes(Posted 2005) [#19]
Hopefully that one was missed by BRL by accident. I remember when the bug bin was created a LOT of random stuff went in there straight away, so this one may have slipped in there without them knowing.