From c1c7db57a4d7e50dc68ead60eeac1c9c1b82db74 Mon Sep 17 00:00:00 2001 From: bofeng Date: Wed, 22 Nov 2023 16:39:29 +0800 Subject: [PATCH 1/3] fix spine can not show normally or crash --- cocos/spine/lib/spine-core.d.ts | 2 +- cocos/spine/skeleton-cache.ts | 2 +- cocos/spine/skeleton.ts | 2 +- .../editor-support/spine-wasm/spine-skeleton-instance.h | 1 - .../editor-support/spine-wasm/spine-skeleton-system.cpp | 6 ------ .../cocos/editor-support/spine-wasm/spine-type-export.cpp | 5 ++--- native/cocos/editor-support/spine-wasm/spine-wasm.cpp | 8 -------- native/cocos/editor-support/spine-wasm/spine-wasm.h | 1 - 8 files changed, 5 insertions(+), 22 deletions(-) diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 8e20f58c144..34956979c5f 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1179,6 +1179,7 @@ declare namespace spine { } class SkeletonSystem { + public static removeSpineInstance(instance: SkeletonInstance): void; public static updateAnimation(deltaTime: number): void; public static updateRenderData(): void; public static getCount(): number; @@ -1219,7 +1220,6 @@ declare namespace spine { static createSpineSkeletonDataWithBinary(byteSize: number, atlasText: string): SkeletonData; static registerSpineSkeletonDataWithUUID(data: SkeletonData, uuid: string); static destroySpineSkeletonDataWithUUID(uuid: string); - static destroySpineInstance(instance: SkeletonInstance); static getCurrentListenerID(): number; static getCurrentEventType(): EventType; static getCurrentTrackEntry(): TrackEntry; diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index df85fea5169..d1debd015fe 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -300,7 +300,7 @@ export class AnimationCache { } public destroy (): void { - spine.wasmUtil.destroySpineInstance(this._instance); + spine.SkeletonSystem.removeSpineInstance(this._instance); } } diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 8cdf6ebc129..71174dd6a5c 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -710,7 +710,7 @@ export class Skeleton extends UIRenderer { this._animCache = null; SkeletonSystem.getInstance().remove(this); if (!JSB) { - spine.wasmUtil.destroySpineInstance(this._instance); + spine.SkeletonSystem.removeSpineInstance(this._instance); } super.onDestroy(); } diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index c34a18fbd64..cb8190cbf1c 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -61,7 +61,6 @@ class SpineSkeletonInstance { bool isCache{false}; bool enable{true}; float dtRate{1.0F}; - bool isDelete{false}; private: void collectMeshData(); diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp index 7537c887f73..681b89f621e 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp @@ -10,12 +10,6 @@ void SpineSkeletonSystem::updateAnimation(float deltaTime) { auto count = static_cast(vectorSpines.size()); for (int i = count - 1; i >= 0; --i) { SpineSkeletonInstance* spineInstance = vectorSpines[i]; - if(spineInstance->isDelete) { - std::swap(spineInstance, vectorSpines.back()); - vectorSpines.pop_back(); - delete spineInstance; - continue; - } if(!spineInstance->enable) continue; if (!spineInstance->isCache) { spineInstance->updateAnimation(deltaTime); diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index cb4a910276e..14c1e41335b 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1588,7 +1588,6 @@ EMSCRIPTEN_BINDINGS(spine) { .constructor<>() .property("isCache", &SpineSkeletonInstance::isCache) .property("dtRate", &SpineSkeletonInstance::dtRate) - .property("isDelete", &SpineSkeletonInstance::isDelete) .property("enable", &SpineSkeletonInstance::enable) .function("initSkeleton", &SpineSkeletonInstance::initSkeleton, allow_raw_pointers()) .function("setAnimation", &SpineSkeletonInstance::setAnimation, allow_raw_pointers()) @@ -1613,7 +1612,8 @@ EMSCRIPTEN_BINDINGS(spine) { class_("SkeletonSystem") .class_function("getCount", &SpineSkeletonSystem::getCount) .class_function("updateAnimation", &SpineSkeletonSystem::updateAnimation) - .class_function("updateRenderData", &SpineSkeletonSystem::updateRenderData); + .class_function("updateRenderData", &SpineSkeletonSystem::updateRenderData) + .class_function("removeSpineInstance", &SpineSkeletonSystem::removeSpineInstance, allow_raw_pointers()); } EMSCRIPTEN_BINDINGS(cocos_spine) { @@ -1626,7 +1626,6 @@ EMSCRIPTEN_BINDINGS(cocos_spine) { .class_function("createSpineSkeletonDataWithBinary", &SpineWasmUtil::createSpineSkeletonDataWithBinary, allow_raw_pointers()) .class_function("registerSpineSkeletonDataWithUUID", &SpineWasmUtil::registerSpineSkeletonDataWithUUID, allow_raw_pointers()) .class_function("destroySpineSkeletonDataWithUUID", &SpineWasmUtil::destroySpineSkeletonDataWithUUID) - .class_function("destroySpineInstance", &SpineWasmUtil::destroySpineInstance, allow_raw_pointers()) .class_function("getCurrentListenerID", &SpineWasmUtil::getCurrentListenerID) .class_function("getCurrentEventType", &SpineWasmUtil::getCurrentEventType) .class_function("getCurrentTrackEntry", &SpineWasmUtil::getCurrentTrackEntry, allow_raw_pointers()) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index 273e83fc59e..ec59ef8b939 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -82,14 +82,6 @@ void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const std::string& uuid) { } } -void SpineWasmUtil::destroySpineInstance(SpineSkeletonInstance* instance) { - if (instance) { - //delete instance; - instance->isDelete = true; - //instance = nullptr; - } -} - uint32_t SpineWasmUtil::queryStoreMemory(uint32_t size) { if (s_mem) { if (s_memSize < size) { diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.h b/native/cocos/editor-support/spine-wasm/spine-wasm.h index 714c6d53e03..e1e0cb6fb66 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.h +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.h @@ -18,7 +18,6 @@ class SpineWasmUtil { static SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr); static void registerSpineSkeletonDataWithUUID(SkeletonData* data, const std::string& uuid); static void destroySpineSkeletonDataWithUUID(const std::string& uuid); - static void destroySpineInstance(SpineSkeletonInstance* instance); static uint32_t getCurrentListenerID(); static EventType getCurrentEventType(); From 1282f1335ba2e039b5344e3ca76d97d8c17b3cef Mon Sep 17 00:00:00 2001 From: bofeng Date: Wed, 22 Nov 2023 17:09:15 +0800 Subject: [PATCH 2/3] refine --- cocos/spine/lib/spine-core.d.ts | 2 +- cocos/spine/skeleton-cache.ts | 2 +- cocos/spine/skeleton.ts | 2 +- .../cocos/editor-support/spine-wasm/spine-skeleton-system.cpp | 2 +- native/cocos/editor-support/spine-wasm/spine-skeleton-system.h | 2 +- native/cocos/editor-support/spine-wasm/spine-type-export.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 34956979c5f..9fdecf2ed5b 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1179,7 +1179,7 @@ declare namespace spine { } class SkeletonSystem { - public static removeSpineInstance(instance: SkeletonInstance): void; + public static destroySpineInstance(instance: SkeletonInstance): void; public static updateAnimation(deltaTime: number): void; public static updateRenderData(): void; public static getCount(): number; diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index d1debd015fe..c39e8d76f83 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -300,7 +300,7 @@ export class AnimationCache { } public destroy (): void { - spine.SkeletonSystem.removeSpineInstance(this._instance); + spine.SkeletonSystem.destroySpineInstance(this._instance); } } diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 71174dd6a5c..a8ae059d356 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -710,7 +710,7 @@ export class Skeleton extends UIRenderer { this._animCache = null; SkeletonSystem.getInstance().remove(this); if (!JSB) { - spine.SkeletonSystem.removeSpineInstance(this._instance); + spine.SkeletonSystem.destroySpineInstance(this._instance); } super.onDestroy(); } diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp index 681b89f621e..5c2ead7f4a1 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp @@ -33,7 +33,7 @@ void SpineSkeletonSystem::addSpineInstance(SpineSkeletonInstance* instance) { vectorSpines.push_back(instance); } -void SpineSkeletonSystem::removeSpineInstance(SpineSkeletonInstance* instance) { +void SpineSkeletonSystem::destroySpineInstance(SpineSkeletonInstance* instance) { auto it = std::find(vectorSpines.begin(), vectorSpines.end(), instance); if (it != vectorSpines.end()) { vectorSpines.erase(it); diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h index 6e47b0a5069..6be9cd9e860 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h @@ -9,7 +9,7 @@ class SpineSkeletonSystem static void updateRenderData(); static int getCount(); static void addSpineInstance(SpineSkeletonInstance* instance); - static void removeSpineInstance(SpineSkeletonInstance* instance); + static void destroySpineInstance(SpineSkeletonInstance* instance); private: static std::vector vectorSpines; }; \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 14c1e41335b..7fbb4e71557 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1613,7 +1613,7 @@ EMSCRIPTEN_BINDINGS(spine) { .class_function("getCount", &SpineSkeletonSystem::getCount) .class_function("updateAnimation", &SpineSkeletonSystem::updateAnimation) .class_function("updateRenderData", &SpineSkeletonSystem::updateRenderData) - .class_function("removeSpineInstance", &SpineSkeletonSystem::removeSpineInstance, allow_raw_pointers()); + .class_function("destroySpineInstance", &SpineSkeletonSystem::destroySpineInstance, allow_raw_pointers()); } EMSCRIPTEN_BINDINGS(cocos_spine) { From 01aebde5ceb0a48c6276c55eceb0c47b17871e5d Mon Sep 17 00:00:00 2001 From: bofeng Date: Thu, 23 Nov 2023 10:44:14 +0800 Subject: [PATCH 3/3] update external version --- native/external-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/external-config.json b/native/external-config.json index fa64669c237..da58d420c61 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-17" + "checkout": "v3.8.2-18" } } \ No newline at end of file