代码运行正常,但电晕模拟器在特定场景冻结

时间:2014-03-27 07:43:59

标签: lua corona

我有一个应用程序在第9个场景继续冻结。我现在正在使用故事板,想法是在玩家回答问题时去一个场景。我使用print语句来确认电晕已进入第10个场景(所有代码都在scene10中运行并运行)但模拟器在场景9处冻结。我尝试将场景9链接到场景1,这也是相同的结果,模拟器屏幕冻结在scene9而不是前往scene1,但场景1中的打印语句显示在模拟器上。代码工作,因为我在每个函数中都有print语句。我拿出一些代码并更改了文件的名称,但没有运气。我还能看到什么?

我还在手机上运行了代码并得到了一些似乎有些错误:

D/CrashAnrDetector( 2962): Hardware: universal5410
D/CrashAnrDetector( 2962): Revision: 10
D/CrashAnrDetector( 2962): Bootloader: I9500ZSUCMK3
D/CrashAnrDetector( 2962): Radio: unknown
D/CrashAnrDetector( 2962): Kernel: Linux version 3.4.5-2138764 (se.infra@R0304-0
8) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT Fri No
v 15 16:58:07 KST 2013

然后会有更多撞击探测器,背后有一堆数字。

D/CrashAnrDetector( 2962):     d0  65746172656e6567  d1  7571207478656e20
D/CrashAnrDetector( 2962):     d2  0000000000000000  d3  0000000000000000
D/CrashAnrDetector( 2962):     d4  0000000000000000  d5  3ff0000000000000
D/CrashAnrDetector( 2962):     d6  c00ffffe00000000  d7  c07ffff000000000
D/CrashAnrDetector( 2962):     d8  40400030c07ffff0  d9  000000003f800000
D/CrashAnrDetector( 2962):     d10 000000003f7fffec  d11 0000000000000000
.....

E/android.os.Debug( 2962): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dump
state_app_error
I/dumpstate(29372): begin
I/dumpstate(29372): dumpstate is still running
....

我可以从中得到的结果是应用程序崩溃了,存储问题似乎有问题?(我认为这就是dumpstate所指的那样?)

local storyboard = require( "storyboard" )
local widget = require "widget"
local scene = storyboard.newScene()

local function returnHome()
storyboard.gotoScene("scene_menu", "crossFade",1000)

return true
end

local physics = require('physics')
physics.start()

-- Clear previous scene


-- local forward references should go here --
local score = 0
local scoreText
local scoreForLevelComplete
local background
local infoBar
local restartBtn
local cannon
local levelNum
local balloon = {}
local cannonCharge = {}
local ballCollision = {}
local shot = {}
local cannonBall
local impulse = 0
local balloons = {}
local cannonCharge = {}
local shot = {}
local cannonBalls = display.newGroup()
local pop = audio.loadSound('pop.mp3')
local wrongAnswer


---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------




function scene:createScene( event )
local group = self.view
storyboard.removeAll()
print('purge scene')
  end

function scene:enterScene(event)
 local group = self.view

background = display.newImage( "bkg_clouds.png")
group:insert(background)
background.x = 230
background.y = 195

scoreText = display.newText( storyboard.state.score, 0, 0, native.systemFont, 32 )
scoreText:setFillColor( 0,0, 0 )
scoreText.x = 87
scoreText.y = 28
group:insert( scoreText ) 

questionText = display.newText('a', display.contentCenterX, display.contentWidth/4, native.systemFont, 40)
group:insert(questionText)

infoBar = display.newImage ("infoBar.png")
group:insert(infoBar)
infoBar.x = 10
infoBar.y = 25

restartBtn = widget.newButton{
defaultFile = "restartBtn.png",
onRelease = returnHome
}
restartBtn.x = 470
restartBtn.y = 300
group:insert(restartBtn)


cannon = display.newImage ("cannon.png")
group:insert(cannon)
cannon.x = 10
cannon.y = 270

cannon.anchorX = 0.5
cannon.anchorY = 0.5
restartBtn.isVisible = true

local MemoryLabel = display.newText( 
    { 
        text = '',
        x = 250,
        y = 220,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
MemoryLabel:setFillColor( 0 )
group:insert(MemoryLabel)

local TextureLabel = display.newText( 
    { 
        text = '',
        x = 250,
        y = 200,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
TextureLabel:setFillColor( 0 )
group:insert(TextureLabel)

-- To check available memory
function checkMemory()
    collectgarbage( "collect" )
    MemoryLabel.text = string.format( "M:%.2f KB", collectgarbage( "count" ) )
    TextureLabel.text = "T:"..(string.format( "%.2f KB", system.getInfo("textureMemoryUsed") / (1024 * 1024)) )

end

timer.performWithDelay( 1000, checkMemory, 0 )


local balloon1 = display.newImage ('balloon_fat_red.png', 495, 70)
local balloon2 = display.newImage ('balloon_fat_red.png', 495, 115)
local balloon3 = display.newImage ('balloon_fat_red.png', 495, 160)

group:insert(balloon1)
group:insert(balloon2)
group:insert(balloon3)

physics.addBody(balloon1)
physics.addBody(balloon2)
physics.addBody(balloon3)

balloon1.bodyType = 'static'
balloon2.bodyType = 'static'
balloon3.bodyType = 'static'

table.insert(balloons, balloon1)      
table.insert(balloons, balloon2)      
table.insert(balloons, balloon3) 

local balloonText1 = display.newText('\227\129\130', 495, 70)
balloonText1:setFillColor( 1,1, 0 )
local balloonText2 = display.newText('\227\129\132', 495, 115)
balloonText2:setFillColor( 1,1, 0 )
local balloonText3 = display.newText('\227\129\134', 495, 160)
balloonText3:setFillColor( 1,1, 0 )


group:insert(balloonText1)
group:insert(balloonText2)
group:insert(balloonText3)

function cannonCharge:touch(event)
  if(event.phase == 'began') then
        impulse = 0
        cannon.isVisible = true
        Runtime:addEventListener('enterFrame', charge)
        print ('cannonCharge')
    end
end

function shot:touch(event)
    if(event.phase == 'ended') then

        Runtime:removeEventListener('enterFrame', charge)
        cannon.isVisible = true
        cannon.rotation = 0

        cannonBall = display.newImage('cannon ball.png', 84, 220)
        physics.addBody(cannonBall, {density = 1, friction = 0, bounce = 0})
        group:insert(cannonBall)
        print ('shot')

-- Shoot cannon ball
cannonBall:applyLinearImpulse(3, impulse, cannonBall.x, cannonBall.y )

--Collision listener
print('event listener')
cannonBall:addEventListener ('collision', ballCollision)

    end
end

function charge()
local degreesPerFrame = 1
cannon.rotation = cannon.rotation - degreesPerFrame 
impulse=impulse-0.2

     if(cannon.rotation < -46) then
          cannon.rotation = -46
          impulse = -3.2
          print('Charge')
        end
end


function ballCollision(event)
   if (event.other == balloons[1])  then
        scene.updateScore()
        print('Ball is colliding')
        balloon1:removeSelf()
        balloon1 = nil
        balloonText1:removeSelf() 
        balloonText1 = nil
        local popSound = audio.play(pop)
        print('Before changing scene')
        storyboard.gotoScene("correct1", "fade", 3000)
  else
   if (event.other == balloons[2])  then
        print('Ball is colliding')
        balloon2:removeSelf()
        balloon2 = nil
        balloonText2:removeSelf() 
        balloonText2 = nil
        local popSound = audio.play(pop)
        print('Before changing scene')
        storyboard.gotoScene("wrong1", "fade", 3000)
  else
   if (event.other == balloons[3])  then
        print('Ball is colliding')
        balloon3:removeSelf()
        balloon3 = nil
        balloonText3:removeSelf() 
        balloonText3 = nil
        local popSound = audio.play(pop)
        print('Before changing scene')
        storyboard.gotoScene("wrong1", "fade", 3000)
    end
    end
    end
end

background:addEventListener('touch', cannonCharge)
background:addEventListener('touch', shot) 
end

function scene.updateScore()
  storyboard.state.score = storyboard.state.score + 50
  scoreText.text = storyboard.state.score
end

-- Called when the scene's view does not exist:


function scene:exitScene(event)
local group = self.view

background:removeEventListener('touch', cannonCharge)
background:removeEventListener('touch', shot)


end

function scene:destroyScene(event)

audio.stop(popSound)
audio.dispose(pop)
popSound = nil
pop = nil
--cannonBall:removeEventListener ('collision', ballCollision)

if restartBtn then
restartBtn:removeSelf()
restartBtn = nil


end

end

scene:addEventListener("createScene", scene)
scene:addEventListener("updateScore", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)

return scene

所以这将进入下一个场景

local storyboard = require( "storyboard" )
local widget = require "widget"
local scene = storyboard.newScene()

local function returnHome()
storyboard.gotoScene("scene_menu", "crossFade",1000)

return true
end

local physics = require('physics')
physics.start()

-- Clear previous scene
storyboard.removeAll()

-- local forward references should go here --

local scoreText
local background
local infoBar
local restartBtn
local cannon
local balloon = {}
local cannonCharge = {}
local ballCollision = {}
local shot = {}
local cannonBall
local impulse = 0
local balloons = {}
local cannonCharge = {}
local shot = {}
local cannonBalls = display.newGroup()
local pop = audio.loadSound('pop.mp3')
local wrongAnswer


---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------




function scene:createScene( event )
local group = self.view
storyboard.removeAll()
print('purge scene')

  end

function scene:enterScene(event)
 local group = self.view

background = display.newImage( "bkg_clouds.png")
group:insert(background)
background.x = 230
background.y = 195

local cannon = display.newImage ("cannon.png")
group:insert(cannon)
cannon.x = 10
cannon.y = 270

scoreText = display.newText( storyboard.state.score, 0, 0, native.systemFont, 32 )
scoreText:setFillColor( 0,0, 0 )
scoreText.x = 87
scoreText.y = 28
group:insert( scoreText ) 

questionText = display.newText('i', display.contentCenterX, display.contentWidth/4, native.systemFont, 40)
group:insert(questionText)

infoBar = display.newImage ("infoBar.png")
group:insert(infoBar)
infoBar.x = 10
infoBar.y = 25

restartBtn = widget.newButton{
defaultFile = "restartBtn.png",
onRelease = returnHome
}
restartBtn.x = 470
restartBtn.y = 300
group:insert(restartBtn)


cannon = display.newImage ("cannon.png")
group:insert(cannon)
cannon.x = 10
cannon.y = 270

cannon.anchorX = 0.5
cannon.anchorY = 0.5
restartBtn.isVisible = true

local MemoryLabel = display.newText( 
    { 
        text = '',
        x = 250,
        y = 220,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
MemoryLabel:setFillColor( 0 )
group:insert(MemoryLabel)

local TextureLabel = display.newText( 
    { 
        text = '',
        x = 250,
        y = 200,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
TextureLabel:setFillColor( 0 )
group:insert(TextureLabel)

-- To check available memory
function checkMemory()
    collectgarbage( "collect" )
    MemoryLabel.text = string.format( "M:%.2f KB", collectgarbage( "count" ) )
    TextureLabel.text = "T:"..(string.format( "%.2f KB", system.getInfo("textureMemoryUsed") / (1024 * 1024)) )

end

timer.performWithDelay( 1000, checkMemory, 0 )

local balloon1 = display.newImage ('balloon_fat_red.png', 495, 70)
local balloon2 = display.newImage ('balloon_fat_red.png', 495, 115)
local balloon3 = display.newImage ('balloon_fat_red.png', 495, 160)

group:insert(balloon1)
group:insert(balloon2)
group:insert(balloon3)

physics.addBody(balloon1)
physics.addBody(balloon2)
physics.addBody(balloon3)

balloon1.bodyType = 'static'
balloon2.bodyType = 'static'
balloon3.bodyType = 'static'

table.insert(balloons, balloon1)      
table.insert(balloons, balloon2)      
table.insert(balloons, balloon3) 

local balloonText1 = display.newText('\227\129\141', 495, 70)
balloonText1:setFillColor( 1,1, 0 )
local balloonText2 = display.newText('\227\129\138', 495, 115)
balloonText2:setFillColor( 1,1, 0 )
local balloonText3 = display.newText('\227\129\132', 495, 160)
balloonText3:setFillColor( 1,1, 0 )


group:insert(balloonText1)
group:insert(balloonText2)
group:insert(balloonText3)

function cannonCharge:touch(event)
  if(event.phase == 'began') then
        impulse = 0
        cannon.isVisible = true
        Runtime:addEventListener('enterFrame', charge)
        print ('cannonCharge')
    end
end

function shot:touch(event)
    if(event.phase == 'ended') then

        Runtime:removeEventListener('enterFrame', charge)
        cannon.isVisible = true
        cannon.rotation = 0

        cannonBall = display.newImage('cannon ball.png', 84, 220)
        physics.addBody(cannonBall, {density = 1, friction = 0, bounce = 0})
        group:insert(cannonBall)
        print ('shot')

-- Shoot cannon ball
cannonBall:applyLinearImpulse(3, impulse, cannonBall.x, cannonBall.y )

--Collision listener
print('event listener')
cannonBall:addEventListener ('collision', ballCollision)

    end
end

function charge()
local degreesPerFrame = 1
cannon.rotation = cannon.rotation - degreesPerFrame 
impulse=impulse-0.2

     if(cannon.rotation < -46) then
          cannon.rotation = -46
          impulse = -3.2
          print('Charge')
        end
end


function ballCollision(event)
   if (event.other == balloons[1])  then
        print('Ball is colliding')
        balloon1:removeSelf()
        balloon1 = nil
        balloon2:removeSelf()
        balloon2 = nil
        balloon3:removeSelf()
        balloon3 = nil


        balloonText1:removeSelf() 
        balloonText1 = nil
        balloonText2:removeSelf() 
        balloonText2 = nil
        balloonText3:removeSelf() 
        balloonText3 = nil
        local popSound = audio.play(pop)
        storyboard.gotoScene("Question3", "fade", 1000)
  else
   if (event.other == balloons[2])  then
        print('Ball is colliding')
        balloon1:removeSelf()
        balloon1 = nil
        balloon2:removeSelf()
        balloon2 = nil
        balloon3:removeSelf()
        balloon3 = nil


        balloonText1:removeSelf() 
        balloonText1 = nil
        balloonText2:removeSelf() 
        balloonText2 = nil
        balloonText3:removeSelf() 
        balloonText3 = nil

        local popSound = audio.play(pop)
        storyboard.gotoScene("Question3", "fade", 1000)
  else
   if (event.other == balloons[3])  then
        scene.updateScore()
        print('Ball is colliding')
        balloon1:removeSelf()
        balloon1 = nil
        balloon2:removeSelf()
        balloon2 = nil
        balloon3:removeSelf()
        balloon3 = nil


        balloonText1:removeSelf() 
        balloonText1 = nil
        balloonText2:removeSelf() 
        balloonText2 = nil
        balloonText3:removeSelf() 
        balloonText3 = nil
        local popSound = audio.play(pop)
        storyboard.gotoScene("Question3", "fade", 1000)
    end
    end
    end
end

background:addEventListener('touch', cannonCharge)
background:addEventListener('touch', shot) 
end

function scene.updateScore()
  storyboard.state.score = storyboard.state.score + 50
  scoreText.text = storyboard.state.score
end

-- Called when the scene's view does not exist:


function scene:exitScene(event)
local group = self.view

cannonBall:removeSelf()
cannonBall = nill

audio.stop(popSound)
audio.dispose(pop)
popSound = nil
pop = nil

background:removeEventListener('touch', cannonCharge)
background:removeEventListener('touch', shot)
physics.stop()
end

function scene:destroyScene(event)


if restartBtn then
restartBtn:removeSelf()
restartBtn = nil
end

end

scene:addEventListener("createScene", scene)
scene:addEventListener("updateScore", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)

return scene

2 个答案:

答案 0 :(得分:0)

真的难以解决,但我会尝试间接回答。

您是否可以尝试将内存调试功能直接添加到电晕中,例如:

oMemoryLabel = display.newText( 
    { 
        text = '',
        x = display.contentWidth*0.33,
        y = display.contentHeiht*0.33,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
oMemoryLabel:setFillColor( 0 )
oGroup:insert(oMemoryLabel)

oTextureLabel = display.newText( 
    { 
        text = '',
        x = display.contentWidth*0.66,
        y = display.contentHeiht*0.66,
        font = 'Arial',
        fontSize = 32,
        align = "center"
    }
)
oTextureLabel:setFillColor( 0 )
oGroup:insert(oTextureLabel)

-- To check available memory
function checkMemory()
    collectgarbage( "collect" )
    oMemoryLabel.text = string.format( "M:%.2f KB", collectgarbage( "count" ) )
    oTextureLabel.text = "T:"..(string.format( "%.2f KB", system.getInfo("textureMemoryUsed") / (1024 * 1024)) )
end

timer.performWithDelay( 1000, checkMemory, 0 )

使用它的两种方法,要么只将它作为一个阶段层加载到其他所有阶段之上,这样它就不会在阶段加载之间卸载,或者你只需​​在每个阶段重新创建它现在...它仍然会给你正确的号码。 如果内存使用或纹理使用在场景,坏消息之间不断增加,你可能会有泄漏或者某些东西没有被正确删除(因此最终会造成奇怪的崩溃)。 祝你好运:)

干杯

答案 1 :(得分:0)

删除场景不会停止场景中的物理,也不会停止任何运行时侦听器。此外,定时器,转换,带回叫的任何内容仍会运行,直到您停止它们为止。如果那些事件与之相关的对象不存在,那么你将会遇到奇怪的崩溃。

确保正确清理场景。