我的应用程序在Corona Simulator中工作正常,但在设备本身崩溃,并在iOS设备控制台中返回以下错误:
Mar 20 22:56:26 tmacs-iPhone backboardd[28] <Warning>: Application 'UIKitApplication:HappyShaker[0x9cf9]' exited abnormally with signal 10: Bus error: 10
Mar 20 22:56:26 tmacs-iPhone backboardd[28] <Warning>: BKSendGSEvent ERROR sending event type 23: (ipc/send) invalid destination port (0x10000003)
根据我的研究,我发现这个错误是由这两个问题引起的:
- 访问不存在的内存
- 访问未在4或8字节边界上对齐的内存
醇>
顺便说一句,Corona的运作方式很可能是第一个原因。
在调试过程中,我发现了一些缩小搜索问题的东西。
下面说明的代码导致应用程序崩溃。它是一个按钮,它启动物理,设置其比例,添加物理对象,启动计时器,并在按下后删除按钮。它有点初始化物理。
local playButton = nil
local function handleButtonEvent( event )
if "ended" == event.phase then
physics.start()
physics.setScale(60)
physics.addBody( red, "dynamic",redBody )
physics.addBody( borderTop, "static", borderBodyElement )
physics.addBody( borderBottom, "static", borderBodyElement )
physics.addBody( borderLeft, "static", borderBodyElement )
physics.addBody( borderRight, "static", borderBodyElement )
timer.performWithDelay(1000, fn_counter, number)
playButton:removeSelf()
playButton = nil
end
return true
end
playButton = widget.newButton {
left = _W/2-53,
top = 400,
width = 105,
height = 39,
defaultFile = "start.png",
overFile = "start_pressed.png",
label = "",
onEvent = handleButtonEvent,
}
playButton.isActive = true
group:insert(playButton)
当我注释掉代码的按钮小部件时,它工作正常并且不会崩溃。注释掉的部分在下面的代码中说明。
-- local playButton = nil
-- local function handleButtonEvent( event )
-- if "ended" == event.phase then
physics.start()
physics.setScale(60)
physics.addBody( red, "dynamic",redBody )
physics.addBody( borderTop, "static", borderBodyElement )
physics.addBody( borderBottom, "static", borderBodyElement )
physics.addBody( borderLeft, "static", borderBodyElement )
physics.addBody( borderRight, "static", borderBodyElement )
timer.performWithDelay(1000, fn_counter, number)
-- playButton:removeSelf()
-- playButton = nil
-- end
-- return true
-- end
-- playButton = widget.newButton {
-- left = _W/2-53,
-- top = 400,
-- width = 105,
-- height = 39,
-- defaultFile = "start.png",
-- overFile = "start_pressed.png",
-- label = "",
-- onEvent = handleButtonEvent,
-- }
-- playButton.isActive = true
-- group:insert(playButton)
有没有人在使用按钮小部件之前遇到此问题?
我还应该提一下,这段代码位于storyboard的createScene()函数中。
答案 0 :(得分:1)
我找到了解决方案。它与physics.start()在侦听器函数内部有关。我做了以下调整:
physics.start()
physics.setScale( 60 )
physics.addBody( borderTop, "static", borderBodyElement )
physics.addBody( borderBottom, "static", borderBodyElement )
physics.addBody( borderLeft, "static", borderBodyElement )
physics.addBody( borderRight, "static", borderBodyElement )
-- local startButton = nil
local function handleButtonEvent( event )
if "ended" == event.phase then
physics.addBody( red, "dynamic",redBody )
timer.performWithDelay(1000, fn_counter, number)
startButton:removeSelf()
startButton = nil
end
return true
end
通过将physics.start()函数放在侦听器事件函数之外使其工作。但是,我仍然对为什么会导致分段错误感到困惑。有人可以向我解释一下吗?