【发布时间】:2014-04-28 13:48:24
【问题描述】:
我有一个在 Corona 模拟器中运行良好的应用程序,但在设备本身上崩溃,并且它在 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)
以前有人在使用按钮小部件时遇到过这个问题吗?
我还应该提到,这段代码位于情节提要的 createScene() 函数中。
【问题讨论】:
标签: ios mobile lua segmentation-fault coronasdk