Negative Texture Memory reported is linked to Default.png

This code works fine and reports 0 texture memory until I add a Default.png to the
folder. It seems to be linked some how to the event. Is there a way to clear the
Default.png from texture memory after the game has loaded or am I doing something
else wrong.

I used the fish images. Code is not Beautified :wink:

[code]
local map = {}
for x=1,8 do
map[x] = {}
for y=1,10 do
map[x][y]={}
end
end
local restart=0

local function gameEventLoop(event)
if restart==1 then
loadMap()
restart=0
end
end

function onTouch( event)
print(“touch restart”)
local t = event.target
local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
elseif t.isFocus then
if “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
–loadMap()
restart=1
end
end

return true
end

function destroyMap()
for x=1,8 do
for y=1,10 do

if (map[x][y].image~= “blank”) then
if (map[x][y].button~=nil) then
map[x][y].button:removeEventListener( “touch”, onTouch )
map[x][y].button:removeSelf()
map[x][y].button=nil
end
if (map[x][y].shadow~=nil) then
map[x][y].shadow:removeSelf()
map[x][y].shadow=nil
end
end
end
end

if (map.imagegroup~=nil) then
print("imagegroup "…map.imagegroup.numChildren)
for i=map.imagegroup.numChildren,1,-1 do
local child = map.imagegroup[i]
child.parent:remove( child )
end
end
map.imagegroup=nil
collectgarbage(“collect”)
print(collectgarbage(“count”))
print( “TextureMemory clear: " … system.getInfo(“textureMemoryUsed”) … " bytes” )

end
function loadMap()

destroyMap()

map.imagegroup =display.newGroup()

for x=1,8 do
for y=1,10 do

map[x][y].button = display.newImageRect(“Image1.png”,40,40)
map[x][y].shadow = display.newImageRect(“Image2.png”,40,40)
map[x][y].shadow.alpha=0.5
map.imagegroup:insert(map[x][y].shadow)
map.imagegroup:insert(map[x][y].button)
map[x][y].button.x=(x)*39+5
map[x][y].button.y=(y)*39+46
map[x][y].shadow.x=(x)*39+11
map[x][y].shadow.y=(y)*39+12
map[x][y].button:addEventListener( “touch”, onTouch )

end
end

collectgarbage(“collect”)
print(collectgarbage(“count”))
print( “TextureMemory finished: " … system.getInfo(“textureMemoryUsed”) … " bytes” )

end

loadMap()
loadMap()
loadMap()
Runtime:addEventListener( “enterFrame”, gameEventLoop )
[/code] [import]uid: 8384 topic_id: 3337 reply_id: 303337[/import]

Hmm, I don’t know but I filed a bug for engineering to take a look (case 1802). If I learn anything new I’ll post back. Thanks for the report.

Tim [import]uid: 8196 topic_id: 3337 reply_id: 10158[/import]

Thanks Tim,

Cleaned the code a bit

[code]
–make sure a Default.png exists
gameState=0

function gameEventLoop(event)
if gameState==1 then
print(“fourth run”)
loadMap()
gameState=0
end
end

function onTouch( event)
print(“touch restart”)
local t = event.target
local phase = event.phase
if “began” == phase then
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )
t.isFocus = true
elseif t.isFocus then
if “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
gameState=1
print(“third run”)
loadMap()
end
end

return true
end

function destroyMap()

if (button~=nil) then
button:removeEventListener( “touch”, onTouch )
button:removeSelf()
button=nil
end

if (imagegroup~=nil) then
print("imagegroup "…imagegroup.numChildren)
for i=imagegroup.numChildren,1,-1 do
local child = imagegroup[i]
child.parent:remove( child )
end
end
imagegroup=nil
collectgarbage(“collect”)
print("collect garbage "…collectgarbage(“count”))
print( “TextureMemory clear: " … system.getInfo(“textureMemoryUsed”) … " bytes” )

end

function loadMap()
destroyMap()
imagegroup =display.newGroup()
button = display.newImageRect(“Image1.png”,40,40)
imagegroup:insert(button)
button.x=50
button.y=50
button:addEventListener( “touch”, onTouch )

collectgarbage(“collect”)
print("collect garbage "…collectgarbage(“count”))
print( “TextureMemory finished: " … system.getInfo(“textureMemoryUsed”) … " bytes” )
end

Runtime:addEventListener( “enterFrame”, gameEventLoop )

print(“first run”)
loadMap()
print(“second run”)
loadMap()
print(“click the fish”)
[/code] [import]uid: 8384 topic_id: 3337 reply_id: 10285[/import]

hey i want my game to restart when i press a button. I have added a button but don’t know how to restart the whole game. Is their any function to for restart? [import]uid: 63289 topic_id: 3337 reply_id: 40247[/import]