Corona SDK 应用程序异常退出,报告信号10:总线错误:10。设备崩溃。

我有一个在 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)

从我的研究发现,这个错误是由以下两个问题引起的:

  1. 访问不存在的内存
  2. 访问没有以 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()函数中。

点赞
用户2020580
用户2020580

我找到了解决方案。这与 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() 函数放在监听事件函数外面使其正常工作。不过,我仍然不清楚为什么这会导致分段错误。有人能向我解释一下吗?

2014-03-21 11:18:23