Skip to content

LeafLayout有小概率会对已销毁元素执行布局 #865

Description

@dawumusic

作者你好,深夜发现一个潜藏的Bug,起因是业务中发现有小概率出现画布崩溃,调试发现Box继承类在执行了destroy()后,被调用了__onUpdateSize方法(里面有一些业务逻辑)。

更进一步调试后发现,原因似乎在LeafLayout类中的destroy函数(当前是空方法),缺少对xxxChanged标记位进行复位赋值,导致在下一次引擎布局判定中(partLayout/fullLayout)若读到存在boxChanged这类的属性为true,就会进一步赋值resized='inner'等,继而触发了后续调用链(__onUpdateSize等)。

也是写了一个最小复现demo,但没复现出来,只在业务中比较复杂的时候偶尔出现...

目前我在业务中直接改了原型链的destroy,没有再出现问题,估计是这部分的原因,或许作者能在更上层有其它的解法。

临时解决代码:

LeafLayout.prototype.destroy = function () {
  this.resized = undefined
  this.boundsChanged = undefined
  this.boxChanged = undefined
  this.surfaceChanged = undefined
  this.hitCanvasChanged = undefined
  // 暂时补了上面这些,其它标记位可能也需要复位
}

相关代码:https://github.com/leaferjs/leafer/blob/9745d2d116c8105bdfb21dae419a93b1eccc0186/packages/display-module/layout/src/LeafLayout.ts

https://github.com/leaferjs/leafer/blob/9745d2d116c8105bdfb21dae419a93b1eccc0186/packages/display-module/display-module/src/LeafBounds.ts

https://github.com/leaferjs/leafer/blob/9745d2d116c8105bdfb21dae419a93b1eccc0186/packages/display-module/helper/src/LeafHelper.ts

调试截图:

Image Image

调用链路线索:

? --> LeafHelper.updateBounds() --> LeafBounds.__updateLocalBounds(),LeafBounds.__updateWorldBounds()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions