[engine] 修复 Spine 动态合图销毁时未考虑多个引用的问题

This commit is contained in:
SmallMain 2022-06-27 17:38:23 +08:00
parent 19a018dc5e
commit 35da03cbdd
4 changed files with 71 additions and 44 deletions

View File

@ -95930,6 +95930,7 @@
var _x, _y, _m00, _m04, _m12, _m01, _m05, _m13; var _x, _y, _m00, _m04, _m12, _m01, _m05, _m13;
var _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da; var _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da;
var _comp, _buffer, _renderer, _node, _needColor, _vertexEffect; var _comp, _buffer, _renderer, _node, _needColor, _vertexEffect;
var _packedRegions = [];
function _getSlotMaterial(tex, blendMode) { function _getSlotMaterial(tex, blendMode) {
var src, dst; var src, dst;
switch (blendMode) { switch (blendMode) {
@ -96055,8 +96056,30 @@
comp._dataDirty = false; comp._dataDirty = false;
} }
}; };
_proto.bindPackedRegion = function bindPackedRegion(attachment, region) {
var frame = region._spriteFrame;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
region._original._ref++;
frame.once("_resetDynamicAtlasFrame", (function() {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original._ref--;
region._original._ref <= 0 && (region._original = null);
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
}));
};
_proto.packDynamicAtlasForSpine = function packDynamicAtlasForSpine(comp) { _proto.packDynamicAtlasForSpine = function packDynamicAtlasForSpine(comp) {
false; false;
_packedRegions.length = 0;
var allowDynamicAtlas = comp.allowDynamicAtlas; var allowDynamicAtlas = comp.allowDynamicAtlas;
if ((cc.sp.allowDynamicAtlas && 0 === allowDynamicAtlas || 1 === allowDynamicAtlas) && cc.dynamicAtlasManager) { if ((cc.sp.allowDynamicAtlas && 0 === allowDynamicAtlas || 1 === allowDynamicAtlas) && cc.dynamicAtlasManager) {
var skins = comp.skeletonData._skeletonCache.skins; var skins = comp.skeletonData._skeletonCache.skins;
@ -96064,10 +96087,10 @@
var skin = _step3.value; var skin = _step3.value;
for (var _iterator4 = _createForOfIteratorHelperLoose(skin.attachments), _step4; !(_step4 = _iterator4()).done; ) { for (var _iterator4 = _createForOfIteratorHelperLoose(skin.attachments), _step4; !(_step4 = _iterator4()).done; ) {
var attachments = _step4.value; var attachments = _step4.value;
var _loop = function _loop(key) { for (var key in attachments) {
var attachment = attachments[key]; var attachment = attachments[key];
var region = attachment.region; var region = attachment.region;
if (region && !region._original && region.texture && region.texture._texture.packable) { if (region) if (region._original) _packedRegions.includes(region) && this.bindPackedRegion(attachment, region); else if (region.texture && region.texture._texture.packable) {
if (region._spriteFrame) { if (region._spriteFrame) {
region._spriteFrame.destroy(); region._spriteFrame.destroy();
region._spriteFrame = null; region._spriteFrame = null;
@ -96079,7 +96102,8 @@
region._original = { region._original = {
_texture: region.texture, _texture: region.texture,
_x: region.x, _x: region.x,
_y: region.y _y: region.y,
_ref: 0
}; };
region.texture = new sp.SkeletonTexture({ region.texture = new sp.SkeletonTexture({
width: packedFrame.texture.width, width: packedFrame.texture.width,
@ -96088,30 +96112,16 @@
region.texture.setRealTexture(packedFrame.texture); region.texture.setRealTexture(packedFrame.texture);
region.x = packedFrame.x; region.x = packedFrame.x;
region.y = packedFrame.y; region.y = packedFrame.y;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
frame.once("_resetDynamicAtlasFrame", (function() {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original = null;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
}));
region._spriteFrame = frame; region._spriteFrame = frame;
this.bindPackedRegion(attachment, region);
_packedRegions.push(region);
} else frame.destroy(); } else frame.destroy();
} }
};
for (var key in attachments) _loop(key);
} }
} }
} }
}
_packedRegions.length = 0;
}; };
_proto.fillVertices = function fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot) { _proto.fillVertices = function fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot) {
var vbuf = _buffer._vData, ibuf = _buffer._iData, uintVData = _buffer._uintVData; var vbuf = _buffer._vData, ibuf = _buffer._iData, uintVData = _buffer._uintVData;

File diff suppressed because one or more lines are too long

View File

@ -74449,6 +74449,7 @@
var _x, _y, _m00, _m04, _m12, _m01, _m05, _m13; var _x, _y, _m00, _m04, _m12, _m01, _m05, _m13;
var _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da; var _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da;
var _comp, _buffer, _renderer, _node, _needColor, _vertexEffect; var _comp, _buffer, _renderer, _node, _needColor, _vertexEffect;
var _packedRegions = [];
function _getSlotMaterial(tex, blendMode) { function _getSlotMaterial(tex, blendMode) {
var src, dst; var src, dst;
switch (blendMode) { switch (blendMode) {
@ -74574,8 +74575,30 @@
comp._dataDirty = false; comp._dataDirty = false;
} }
}; };
_proto.bindPackedRegion = function bindPackedRegion(attachment, region) {
var frame = region._spriteFrame;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
region._original._ref++;
frame.once("_resetDynamicAtlasFrame", (function() {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original._ref--;
region._original._ref <= 0 && (region._original = null);
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
}));
};
_proto.packDynamicAtlasForSpine = function packDynamicAtlasForSpine(comp) { _proto.packDynamicAtlasForSpine = function packDynamicAtlasForSpine(comp) {
false; false;
_packedRegions.length = 0;
var allowDynamicAtlas = comp.allowDynamicAtlas; var allowDynamicAtlas = comp.allowDynamicAtlas;
if ((cc.sp.allowDynamicAtlas && 0 === allowDynamicAtlas || 1 === allowDynamicAtlas) && cc.dynamicAtlasManager) { if ((cc.sp.allowDynamicAtlas && 0 === allowDynamicAtlas || 1 === allowDynamicAtlas) && cc.dynamicAtlasManager) {
var skins = comp.skeletonData._skeletonCache.skins; var skins = comp.skeletonData._skeletonCache.skins;
@ -74583,10 +74606,10 @@
var skin = _step3.value; var skin = _step3.value;
for (var _iterator4 = _createForOfIteratorHelperLoose(skin.attachments), _step4; !(_step4 = _iterator4()).done; ) { for (var _iterator4 = _createForOfIteratorHelperLoose(skin.attachments), _step4; !(_step4 = _iterator4()).done; ) {
var attachments = _step4.value; var attachments = _step4.value;
var _loop = function _loop(key) { for (var key in attachments) {
var attachment = attachments[key]; var attachment = attachments[key];
var region = attachment.region; var region = attachment.region;
if (region && !region._original && region.texture && region.texture._texture.packable) { if (region) if (region._original) _packedRegions.includes(region) && this.bindPackedRegion(attachment, region); else if (region.texture && region.texture._texture.packable) {
if (region._spriteFrame) { if (region._spriteFrame) {
region._spriteFrame.destroy(); region._spriteFrame.destroy();
region._spriteFrame = null; region._spriteFrame = null;
@ -74598,7 +74621,8 @@
region._original = { region._original = {
_texture: region.texture, _texture: region.texture,
_x: region.x, _x: region.x,
_y: region.y _y: region.y,
_ref: 0
}; };
region.texture = new sp.SkeletonTexture({ region.texture = new sp.SkeletonTexture({
width: packedFrame.texture.width, width: packedFrame.texture.width,
@ -74607,30 +74631,16 @@
region.texture.setRealTexture(packedFrame.texture); region.texture.setRealTexture(packedFrame.texture);
region.x = packedFrame.x; region.x = packedFrame.x;
region.y = packedFrame.y; region.y = packedFrame.y;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
frame.once("_resetDynamicAtlasFrame", (function() {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original = null;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) attachment.updateUVs(); else {
attachment.setRegion(region);
attachment.updateOffset();
}
}));
region._spriteFrame = frame; region._spriteFrame = frame;
this.bindPackedRegion(attachment, region);
_packedRegions.push(region);
} else frame.destroy(); } else frame.destroy();
} }
};
for (var key in attachments) _loop(key);
} }
} }
} }
}
_packedRegions.length = 0;
}; };
_proto.fillVertices = function fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot) { _proto.fillVertices = function fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot) {
var vbuf = _buffer._vData, ibuf = _buffer._iData, uintVData = _buffer._uintVData; var vbuf = _buffer._vData, ibuf = _buffer._iData, uintVData = _buffer._uintVData;

View File

@ -251,11 +251,17 @@ export default class SpineAssembler extends Assembler {
attachment.updateOffset(); attachment.updateOffset();
} }
region._original._ref++;
frame.once("_resetDynamicAtlasFrame", () => { frame.once("_resetDynamicAtlasFrame", () => {
region.x = region._original._x; region.x = region._original._x;
region.y = region._original._y; region.y = region._original._y;
region.texture = region._original._texture; region.texture = region._original._texture;
region._original._ref--;
if (region._original._ref <= 0) {
region._original = null; region._original = null;
}
// update uv // update uv
sp.SkeletonData.updateRegionUV(region); sp.SkeletonData.updateRegionUV(region);
@ -303,6 +309,7 @@ export default class SpineAssembler extends Assembler {
_texture: region.texture, _texture: region.texture,
_x: region.x, _x: region.x,
_y: region.y, _y: region.y,
_ref: 0,
}; };
region.texture = new sp.SkeletonTexture({ region.texture = new sp.SkeletonTexture({