Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spine can not show normally or crash #16528

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cocos/spine/lib/spine-core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
duration: number;
name: string;
timelines: Array<Timeline>;
apply(skeleton: Skeleton, lastTime: number, time: number, loop: boolean, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 48 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 166. Maximum allowed is 150
hasTimeline(id: number): boolean;
}
interface Timeline {
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 52 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
getPropertyId(): number;
}
enum MixBlend {
Expand Down Expand Up @@ -92,7 +92,7 @@
getCurveType(frameIndex: number): number;
setCurve(frameIndex: number, cx1: number, cy1: number, cx2: number, cy2: number): void;
getCurvePercent(frameIndex: number, percent: number): number;
abstract apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 95 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 160. Maximum allowed is 150
}
class RotateTimeline extends CurveTimeline {
static ENTRIES: number;
Expand All @@ -104,7 +104,7 @@
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, degrees: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 107 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class TranslateTimeline extends CurveTimeline {
static readonly ENTRIES: number;
Expand All @@ -112,17 +112,17 @@
constructor(frameCount: number);
getPropertyId(): number;
setFrame(frameIndex: number, time: number, x: number, y: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 115 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class ScaleTimeline extends TranslateTimeline {
constructor(frameCount: number);
getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 120 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class ShearTimeline extends TranslateTimeline {
constructor(frameCount: number);
getPropertyId(): number;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 125 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class ColorTimeline extends CurveTimeline {
static ENTRIES: number;
Expand All @@ -133,7 +133,7 @@
getSlotIndex(): number;
setSlotIndex(inValue: number): void;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 136 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class TwoColorTimeline extends CurveTimeline {
static readonly ENTRIES: number;
Expand All @@ -144,7 +144,7 @@
getSlotIndex(): number;
setSlotIndex(inValue: number): void;
setFrame(frameIndex: number, time: number, r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 147 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class AttachmentTimeline implements Timeline {
slotIndex: number;
Expand All @@ -157,7 +157,7 @@
setSlotIndex(inValue: number): void;
getAttachmentNames(): Array<string>;
setFrame(frameIndex: number, time: number, attachmentName: string): void;
apply(skeleton: Skeleton, lastTime: number, time: number, events: Array<Event>, alpha: number, blend: MixBlend, direction: MixDirection): void;

Check warning on line 160 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 151. Maximum allowed is 150
}
class DeformTimeline extends CurveTimeline {
slotIndex: number;
Expand Down Expand Up @@ -779,7 +779,7 @@
MipMapNearestNearest = 9984,
MipMapLinearNearest = 9985,
MipMapNearestLinear = 9986,
MipMapLinearLinear = 9987

Check failure on line 782 in cocos/spine/lib/spine-core.d.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Duplicate enum member value 9987
}
enum TextureWrap {
MirroredRepeat = 33648,
Expand Down Expand Up @@ -1179,6 +1179,7 @@
}

class SkeletonSystem {
public static removeSpineInstance(instance: SkeletonInstance): void;
bofeng-song marked this conversation as resolved.
Show resolved Hide resolved
public static updateAnimation(deltaTime: number): void;
public static updateRenderData(): void;
public static getCount(): number;
Expand Down Expand Up @@ -1219,7 +1220,6 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion cocos/spine/skeleton-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@
const vPtr = model.vPtr;
const vLength = vc * Float32Array.BYTES_PER_ELEMENT * floatStride;
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
vUint8Buf.set(HEAPU8.subarray(vPtr, vPtr + vLength));

Check failure on line 177 in cocos/spine/skeleton-cache.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `ArrayLike<number>`

const iPtr = model.iPtr;
const iLength = Uint16Array.BYTES_PER_ELEMENT * ic;
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
const iUint8Buf = new Uint8Array(iUint16Buf.buffer);
iUint8Buf.set(HEAPU8.subarray(iPtr, iPtr + iLength));

Check failure on line 183 in cocos/spine/skeleton-cache.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `ArrayLike<number>`

const modelData = new SpineModel();
modelData.vCount = vc;
Expand Down Expand Up @@ -300,7 +300,7 @@
}

public destroy (): void {
spine.wasmUtil.destroySpineInstance(this._instance);
spine.SkeletonSystem.removeSpineInstance(this._instance);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/spine/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class SpineSkeletonInstance {
bool isCache{false};
bool enable{true};
float dtRate{1.0F};
bool isDelete{false};
private:
void collectMeshData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ void SpineSkeletonSystem::updateAnimation(float deltaTime) {
auto count = static_cast<int>(vectorSpines.size());
for (int i = count - 1; i >= 0; --i) {
SpineSkeletonInstance* spineInstance = vectorSpines[i];
if(spineInstance->isDelete) {
std::swap(spineInstance, vectorSpines.back());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spineInstance's value will be set to vectorSpines.back(), and delete spineInstance operation will trigger the last element of the vector to destroy

vectorSpines.pop_back();
delete spineInstance;
continue;
}
if(!spineInstance->enable) continue;
if (!spineInstance->isCache) {
spineInstance->updateAnimation(deltaTime);
Expand Down
5 changes: 2 additions & 3 deletions native/cocos/editor-support/spine-wasm/spine-type-export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -1613,7 +1612,8 @@ EMSCRIPTEN_BINDINGS(spine) {
class_<SpineSkeletonSystem>("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) {
Expand All @@ -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())
Expand Down
8 changes: 0 additions & 8 deletions native/cocos/editor-support/spine-wasm/spine-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion native/cocos/editor-support/spine-wasm/spine-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading