[LayaAir 1.0]使用对象池重复使用skeleton报错,请问有解决方案吗?谢谢
引擎版本:1.7.19
描述:
使用对象池重复使用skeleton报错,但每次new Laya.Skeleton() 就没问题。
伪代码:
const temp = new Laya.Templet();
temp.parseData(xxx, xxx, 0);
// 从对象池中获取skeleton
const skeleton = Laya.Pool.getItemByClass('abc', Laya.Skeleton);
skeleton.init(temp, 0);
// skeleton使用完放入对象池
Laya.Pool.recover('abc', skeleton);
报错信息:
laya.core.js:6194 Uncaught TypeError: Cannot read property 'visible' of null
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RenderSprite3D.__proto._transform (laya.webgl.js:6730)
at Character.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RenderSprite3D.__proto._graphics (laya.core.js:6125)
at Owner.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at Component.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RoomBattle.__proto.render (laya.core.js:15656)
__proto._childs @ laya.core.js:6194
__proto._transform @ laya.webgl.js:6730
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto._graphics @ laya.core.js:6125
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto._transform @ laya.webgl.js:6730
__proto.render @ laya.core.js:15656
__proto.render @ laya.core.js:18592
__proto._loop @ laya.core.js:18522
loop @ laya.core.js:5442
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
描述:
使用对象池重复使用skeleton报错,但每次new Laya.Skeleton() 就没问题。
伪代码:
const temp = new Laya.Templet();
temp.parseData(xxx, xxx, 0);
// 从对象池中获取skeleton
const skeleton = Laya.Pool.getItemByClass('abc', Laya.Skeleton);
skeleton.init(temp, 0);
// skeleton使用完放入对象池
Laya.Pool.recover('abc', skeleton);
报错信息:
laya.core.js:6194 Uncaught TypeError: Cannot read property 'visible' of null
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RenderSprite3D.__proto._transform (laya.webgl.js:6730)
at Character.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RenderSprite3D.__proto._graphics (laya.core.js:6125)
at Owner.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at Component.__proto.render (laya.core.js:15656)
at RenderSprite3D.__proto._childs (laya.core.js:6194)
at RoomBattle.__proto.render (laya.core.js:15656)
__proto._childs @ laya.core.js:6194
__proto._transform @ laya.webgl.js:6730
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto._graphics @ laya.core.js:6125
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto.render @ laya.core.js:15656
__proto._childs @ laya.core.js:6194
__proto._transform @ laya.webgl.js:6730
__proto.render @ laya.core.js:15656
__proto.render @ laya.core.js:18592
__proto._loop @ laya.core.js:18522
loop @ laya.core.js:5442
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
requestAnimationFrame (async)
loop @ laya.core.js:5443
没有找到相关结果
已邀请:
要回复问题请先登录
3 个回复
Aar0n
赞同来自:
Milhous
赞同来自:
我在你们官网的引擎示例里的骨骼动画--多纹理,执行下面的测试代码,测试代码是改的示例代码,第一次点击屏幕播放没问题,播放完后Skeleton放入对象池, 第二次点击屏幕使用对象池里的Skeleton播放,就报错了,是不是你们引擎的对象池不支持Skeleton或者是我的使用姿势不对?麻烦看看,谢谢。
测试地址:http://layaair.ldc.layabox.com ... xture
测试代码:
(function()
{
var Skeleton = Laya.Skeleton;
var Templet = Laya.Templet;
var Event = Laya.Event;
var Browser = Laya.Browser;
var Stat = Laya.Stat;
var WebGL = Laya.WebGL;
var Pool = Laya.Pool;
var mAniPath;
var mStartX = 400;
var mStartY = 500;
var mFactory;
var mActionIndex = 0;
var mCurrIndex = 0;
var mArmature;
var mCurrSkinIndex = 0;
(function()
{
WebGL.enable();
Laya.init(Browser.width, Browser.height);
Laya.stage.bgColor = "#ffffff";
Stat.show();
startFun();
})();
function startFun()
{
mAniPath = "res/spine/spineRes1/dragon.sk";
mFactory = new Templet();
mFactory.on(Event.COMPLETE, this, parseComplete);
mFactory.on(Event.ERROR, this, onError);
mFactory.loadAni(mAniPath);
}
function onError()
{
trace("error");
}
function parseComplete() {
Laya.stage.on(Event.CLICK, this, () => {
mArmature = Laya.Pool.getItemByClass('Skeleton', Laya.Skeleton);
mArmature.init(mFactory, 1);
mArmature.x = mStartX;
mArmature.y = mStartY;
mArmature.scale(0.5, 0.5);
mArmature.on(Event.STOPPED, this, completeHandler);
Laya.stage.addChild(mArmature);
play();
});
}
function completeHandler()
{
mArmature.stop();
mArmature.removeSelf();
mArmature.removeChildren();
mArmature.destroy(true);
Laya.Pool.recover('Skeleton', mArmature);
}
function play()
{
mCurrIndex++;
if (mCurrIndex >= mArmature.getAnimNum())
{
mCurrIndex = 0;
}
mArmature.play(mCurrIndex, false);
}
})();
报错信息:
laya.core.js:18207 Uncaught TypeError: Cannot read property 'scaleX' of null
at Skeleton.__proto.scale (VM471 laya.core.js:18207)
at Laya.stage.on (<anonymous>:47:14)
at EventHandler.__proto.runWith (VM471 laya.core.js:950)
at Stage.__proto.event (VM471 laya.core.js:707)
at TouchManager.__proto.sendEvents (VM471 laya.core.js:1511)
at TouchManager.__proto.onMouseUp (VM471 laya.core.js:1670)
at MouseManager.__proto.onMouseUp (VM471 laya.core.js:2658)
at MouseManager.__proto.check (VM471 laya.core.js:2685)
at MouseManager.__proto.runEvent (VM471 laya.core.js:2733)
at HTMLCanvasElement.<anonymous> (VM471 laya.core.js:2556)
__proto.scale @ laya.core.js:18207
Laya.stage.on @ VM2161:47
__proto.runWith @ laya.core.js:950
__proto.event @ laya.core.js:707
__proto.sendEvents @ laya.core.js:1511
__proto.onMouseUp @ laya.core.js:1670
__proto.onMouseUp @ laya.core.js:2658
__proto.check @ laya.core.js:2685
__proto.runEvent @ laya.core.js:2733
(anonymous) @ laya.core.js:2556
menthol
赞同来自: