Hi Silverman,
I had a chance to run your original code I do see a memory leak in video ram when I test system dmem available().
Also note that GET IMAGE 0,0,31,31 only grabs 31X31 pixels so your memblock calculations may be off.
I did some tests and it doesn't seem to be the texturing of the object, but I do think it could be indirectly related.
The leak seems to be from the image being converted from either system memory to video memory or from raw data to a direct draw surface.
There is no leak in making the image from a memblock - but there is a leak when the image data is deleted and the same image reused. So you've opened my eyes to some potential problems with what I thought was working in the past.
I have a solution for your code. We make a bitmap out of the memblock and capture that as an image. This both updates the image and avoids the memory leak. I've made slight adjustments to your code:
remstart
Rotating plasma cube (DarkBasic 1.13 version)
(C) Deckard, AtD, 2004
remend
set display mode 1024,768,32
sync on
sync rate 50
dim sit(255)
hide mouse
autocam off
for i=0 to 255
sit(i)=int(127.0*(1.0+sin(i*360.0/256.0)))
next i
create bitmap 1,32,32
make memblock from bitmap 1,1
delete bitmap 1
k=0
m=0
a=0
mode=1
obj=1
make object cube obj,-50
ghost object on obj
get image 1,0,0,31,31
col=56 : color backdrop rgb(col,col,col)
set current bitmap 0
do
`text 0,0,"Total system memory available = "+str$(mem_available())+" Mo"
text 0,0,"total video mem = "+str$(system dmem available()& rgb(255,255,255))
`REMARK THIS LINE TO STOP THE LEAK
`delete image 1
if deletedmemblock!1
delete memblock 1
make memblock 1,12+(32*32*(screen depth()/8))
write memblock dword 1,0,32
write memblock dword 1,4,32
write memblock dword 1,8,32
deletedmemblock=1
endif
k=(k+1)&255
m=(m+3)&255
for j=0 to 31
for i=0 to 31
p=12+((i+(j*32))*4)
r=sit(sit(sit((sit(i)+sit((j+m)&255)-sit(k))&255)))
g=sit(sit((sit(3*i)+sit((4*j+k)&255)+sit(m))&255))
b=sit(sit((sit(2*i)+sit(3*j)+sit(k))&255))
write memblock dword 1,p,rgb(r,g,b)
next i
next j
remstart
p=12
for j=0 to 31
for i=0 to 31
` plasma RGB value calculation
r=sit(sit(sit((sit(i)+sit((j+m)&255)-sit(k))&255)))
g=sit(sit((sit(3*i)+sit((4*j+k)&255)+sit(m))&255))
b=sit(sit((sit(2*i)+sit(3*j)+sit(k))&255))
write memblock byte 1,p,b
p=p+1
write memblock byte 1,p,g
p=p+1
write memblock byte 1,p,r
p=p+2
next i
next j
remend
make bitmap from memblock 1,1
set current bitmap 1
get image 1,0,0,32,32
set current bitmap 0
a=wrapvalue(a+1)
if a=0
mode=1-mode
endif
set object obj,1,1,0,mode,0,0,0
texture object obj,1
position camera 10*sin(a),11*sin(a),8*cos(a)
point camera 0,0,0
if spacekey() then paste image 1,0,0
sync
loop
end
function mem_available()
`524288 = 512*1024
memory#=SHR(system smem available(),1)/524288.0
endfunction memory#
rem shift bits on the right
function SHR(p,displacement)
if displacement>=0 and displacement<32
sgn=(p<0)*(2^(31-displacement))
tmp2=(p&2147483647)/(2^displacement)
result=(sgn|tmp2)
else
result=0
endif
endfunction result
Enjoy your day.