TTF Label历史创建数量过多,会崩溃,之前没有做过这么多label的游戏, 经验不足,大家给看看
截图:
-
Creator 版本: 2.4.2
-
目标平台: 模拟器 / 安卓真机
-
重现方式:ccc模拟器运行demo,等待2-4s即可;真机每次创建150个label,第二次崩溃;
-
首个报错: 模拟器调试窗口没有错误输出,直接弹框;ccc开发者工具关闭弹窗后可以看到: E/renderer (665): ccBindBuffer(0x8893, ib ? ib->getHandle(): 0); GL error 0x505: GL_OUT_OF_MEMORY:cocos2d::renderer::DeviceGraphics::restoreIndexBuffer
-
之前哪个版本是正常的: 之前没做过用这么多label的游戏, 参考意义不大;
-
手机型号: 红米A6
-
手机浏览器: 浏览器基本没问题;
-
编辑器操作系统: windows 10
-
重现概率: 100%
-
demo附件:CrashTest.zip (1014.5 KB)
源码:
const {ccclass, property} = cc._decorator;
@ccclass
export default class CrashTest extends cc.Component {
@property(cc.Node)
prefab:cc.Node = null;
start() {
let i = 0;
let f = () => {
i++;
if (i % 2 == 0) {
this.node.destroyAllChildren();
} else {
for (let j = 1; j <= 500; j++) {
let n = cc.instantiate(this.prefab);
this.node.addChild(n);
}
}
};
this.schedule(f, 2, cc.macro.REPEAT_FOREVER, 0.01)
}
}
prefab就是Label节点;