Is there any way to remove active textures from the memory? Perhaps by some pokeing of the heap perhaps if addresses could be known?
Whilst generally assuming good tracking of textures is used, this shouldn't be an issue, but perhaps there's a risk that textures (especially those not applied via file or brush) may get left active and forgotten about and the emory gets eaten up it seems without any means to free it aside from destroying the entity it's attached to.
Graphics3D 1024,768,32,6
SetBuffer BackBuffer()
SeedRnd MilliSecs()
Global Cam=CreateCamera()
CameraFogRange Cam,0,50
AmbientLight 80,96,84
Global camlight=CreateLight(3)
LightColor camlight,192,192,184
LightConeAngles camlight,5,60
LightRange camlight,10
EntityParent camlight,Cam,1
Global cube=CreateCube()
EntityAutoFade cube,5,50
EntityColor cube,Rand(255),Rand(255),Rand(255)
x#=Rnd(0.1,2.0)
ScaleMesh cube,x#,x#,x#
EntityShininess cube,Rnd(0.4,1.0)
PositionEntity cube,0,MeshHeight(cube),5
plane=CreatePlane()
EntityAutoFade plane,25,50
Global ptex=CreateTexture(128,128,264)
SetBuffer TextureBuffer(ptex)
ClsColor 192,192,192
Cls
Color 64,64,64
Rect 0,0,64,64,1
Rect 63,63,64,64,1
SetBuffer BackBuffer()
EntityTexture plane,ptex
FreeTexture ptex
ptex=0
MoveEntity Cam,0,1,0
MoveMouse 512,384
While Not KeyDown(1)
MoveEntity Cam,KeyDown(205)-KeyDown(203),0,KeyDown(200)-KeyDown(208)
ShowPointer
TurnEntity Cam,MouseY()-384,512-MouseX(),0,1
RotateEntity Cam,EntityPitch(Cam,1),EntityYaw(Cam,1),0,1
MoveMouse 512,384
HidePointer
If MouseHit(1) Then AddATexture
If MouseHit(2) Then FreeATexture
UpdateWorld
RenderWorld
Color 32,32,32
Rect 0,0,1024,60,1
Color 32,255,32
Text 0,0,"LEFT MOUSE=ADD NEW TEXTURE, RIGHT MOUSE=FREE TEXTURE"
Text 0,30,Str(ActiveTextures())
Flip
Delay 10
Wend
ClearWorld 1,1,1
EndGraphics
End
Function AddATexture()
If (ptex)
; FreeTexture ptex
; ptex=0
End If
ptex=CreateTexture(128,128,264)
SetBuffer TextureBuffer(ptex)
Color Rand(255),Rand(255),Rand(255)
n=Rand(4,128)
For f=4 To n Step 2
Oval 64-(f*0.5),64-(f*0.5),f,f,0
Next
SetBuffer BackBuffer()
EntityTexture cube,ptex
End Function
Function FreeATexture()
If (ptex)
FreeTexture ptex
ptex=0
End If
End Function
In this code, the commented section represents the tracking. Fortunately, this is simplified and very possible here due in part to the use of a single, global, however, its not always practical.
|