cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.42k stars 1.97k forks source link

[spine相关] 动态修改 Skin 后, 后续再使用该skin 报`null function or function signature mismatch` 错误 #17444

Open finscn opened 3 months ago

finscn commented 3 months ago

Cocos Creator version

3.8.3

System information

all

Issue description

    const skeletonData = anim.skeletonData.getRuntimeData();
    const skin: sp.spine.Skin = skeletonData.findSkin(skinName);

获得 skin后, 对skin 进行修改, 比如执行

skin.setAttachment(...) 或  skin.removeAttachment(...)

后续涉及到此skin的代码会报错: null function or function signature mismatch

image image

Relevant error log output

No response

Steps to reproduce

.

Minimal reproduction project

No response

bofeng-song commented 3 months ago

@finscn 问题分析: skin.setAttachment(...) 最终会释放 旧的 attachment image

如果attachment是从其他的slot copy或直接设置到新的slot上,旧的slot上的attchment指针还在 image

由于setAttachMent 释放了 slot持有的attachment对象,所以对象无效。

如果你的demo是类似这种情况,需要你增加旧的attachement的引用,spine-type-export上 Attachment增加 reference的导出 或者拿到slot后,同时更新slot上的attachment。底层逻辑用的是第三方spine源码,这部分引擎没动过

bofeng-song commented 3 months ago

参考demo image

finscn commented 3 months ago

@bofeng-song "spine-type-export上 Attachment增加 reference的导出" 这个能否官方实现? 不想自定义引擎.

另外 从你的描述来看 有两个方案 "增加 reference的导出 或者 拿到slot后同时更新slot上的attachment" "或者"后面的那个方案没看懂, 有demo 吗? 谢谢

bofeng-song commented 3 months ago

@finscn slot 上重新设置attachment的方式是类似: image