-
Creator 版本: 3.8.3
-
目标平台: chrome浏览器调试
-
重现方式:创建一个spine对象,重复设置setCompleteListener, TrackEntryListeners._listenerSet会一直增长,就算setCompleteListener(null)也没用,
static addListener (listener: CommonTrackEntryListener): number {
const id = ++_listener_ID;
TrackEntryListeners._listenerSet.set(id, listener);
return id;
}
这个方法只会一直累加
2赞
遇到了同样的问题, 内存会缓慢增加, 最后游戏崩溃, 你解决掉了么
h5平台的才会出现这个问题,我暂时重写方法解决
if (!sys.isNative) {
sp.Skeleton.prototype["setCompleteListener"] = function (listener: __private._cocos_spine_skeleton__TrackListener) {
this._ensureListener();
let savelistenerID = this["_listenerID"]
if (savelistenerID) {
this._instance!.setListener(savelistenerID, null);
if (globalThis.TrackEntryListeners._listenerSet) {
globalThis.TrackEntryListeners._listenerSet.delete(savelistenerID);
}
}
if (listener) {
const listenerID = globalThis.TrackEntryListeners.addListener(listener);
this["_listenerID"] = listenerID
this._instance!.setListener(listenerID, sp.spine.EventType.complete);
}
if (this._listener) {
this._listener!.complete = listener;
}
}
sp.Skeleton.prototype["setEventListener"] = function (listener: __private._cocos_spine_skeleton__TrackListener2) {
this._ensureListener();
let savelistenerID = this["_listenerID2"]
if (savelistenerID) {
this._instance!.setListener(savelistenerID, null);
if (globalThis.TrackEntryListeners._listenerSet) {
globalThis.TrackEntryListeners._listenerSet.delete(savelistenerID);
}
}
if (listener) {
const listenerID = globalThis.TrackEntryListeners.addListener(listener);
this["_listenerID2"] = listenerID
this._instance!.setListener(listenerID, sp.spine.EventType.event);
}
if (this._listener) {
this._listener!.event = listener;
}
}
sp.Skeleton.prototype["onDestroyClone"] = sp.Skeleton.prototype["onDestroy"];
sp.Skeleton.prototype["onDestroy"] = function (){
this.setEventListener(null)
this.setCompleteListener(null)
this.onDestroyClone();
}
}