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

[spine-c] Fix crashes in skins or animations error handling #2491

Merged
merged 4 commits into from Apr 30, 2024

Conversation

DimonSE
Copy link
Contributor

@DimonSE DimonSE commented Mar 26, 2024

Good day,

I've implemented additional fixes related to pull request #2276, aimed at correctly unloading the spine skeleton when encountering skin or animation errors.

In most cases, everything works well as is, but sometimes crashes occurred because, in case of some problems, it is necessary to call spSkeletonData_dispose(), which tries to clear all skins and animations, even those that have not fully loaded or were not loaded at all.

In SkeletonJson, the fix is quite simple; I just adopted the approach used in the /* Bones. */ section, where skeletonData->bonesCount++; is only called at the end, instead of immediately setting skeletonData->bonesCount = bones->size;
This allows spSkeletonData_dispose() to clear only those bones that were actually created, rather than attempting to delete all bones. I simply repeated this approach for slots, various constraints, and animations.
Thus, no matter at what stage of loading inside spSkeletonJson_readSkeletonData() an exit from the function is made, skeletonData will be correctly deleted without crashes when an error happened, and I will get a valid string in pSkelJson->error; with a detailed description of what exactly is wrong.

SkeletonBinary.c required simpler adjustments, mainly reducing error checks to skins and animations.
I've limited the deletion scope by setting skeletonData->skinsCount = i + 1; and skeletonData->animationsCount = i + 1; in their respective error handlers.

Additionally, service function calls were added to minimize memory leaks during erroneous skeleton processing.

These enhancements help our team of animators and designers to independently obtain more information when checking animations, specifically which skin or animation was broken, allowing them to more frequently identify problems themselves by using our internal 'assets viewer' to check .skel files, without involving game programmers to debug the issue.

…specific cases during update bones, cause squared value can been very smoll but still negative anyway and create NaN value
…eton in SkeletonBinary/SkeletonJson.

Use increase counts instead directly put counts value for avoid problems at early dispose vectors
@badlogic badlogic merged commit f67807f into EsotericSoftware:4.2 Apr 30, 2024
@badlogic
Copy link
Collaborator

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants