• Runtimes
  • Hard crash with a missing attachment

My game is hard crashing because an artist didn't correctly add an attachment. It's crashing in this line...

for (attachmentsMap = Json::getItem(skinMap, "attachments")->_child; attachmentsMap; attachmentsMap = attachmentsMap->_next) 

...because getItem(skinMap, "attachments") is returning nullptr and no check is done before dereferencing.

Is there a clean way for me to check this after I load (or before the animation is played) so there isn't a hard crash and a more polite error? Hard crashes might be OK if you're running Xcode or VS, but for someone just testing their work in the game it's frustrating. I'd like to add clean errors when possible. I could modify the source, but I'd rather not change the Spine source.

Related Discussions
...

What version of Spine editor are you using? What version of the Spine Runtimes?

Spine should never export data that crashes when loaded at runtime. Can you please send your .spine file so we can export and see the runtime crash? contact@esotericsoftware.com

a month later

The data and export are fine. The issue is the if the runtimes call getItem(skinMap, "attachments") with an attachment that doesn't exist it crashes. Its crashing because you call this function and immediately dereference it without checking to see if it returned nullptr.

Json::getItem(skinMap, "attachments")->_child

I fixed this my going into the run-time code and checking getItem() before dereferencing it with ->_child.

The point still stands that Spine shouldn't export data with missing attachments. Could you share your project file and exports?