Forgive any errors here, I'm a coding hobbyist and a newbie to SO question asking, but have done my best to track down this bug and failed.
I'm getting a crash moving between SKScenes, but only if the app has gone into, and been restored from, background mode. Also the crash only happens on an actual device, not on simulator. The output from the console is this:
2018-12-22 15:17:32.646668+0000 grabbit[22230:5424629] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectsInRange:]: range {0, 2} extends beyond bounds [0 .. 0]'
*** First throw call stack:
(0x210febea0 0x2101bda40 0x210f63470 0x210ed32ac 0x2288df1a0 0x2288df438 0x2288b13d8 0x2101bc468 0x2101cc70c 0x2101cc774 0x22880fe18 0x1040764d4 0x2101bc468 0x2101cc70c 0x2101cc774 0x23e1e56cc 0x2288911e8 0x228845c5c 0x104076430 0x104076468 0x1040b92ec 0x1040b9390 0x22886c1b0 0x23e1f418c 0x23e1f53f0 0x23e1d46ec 0x23e2a057c 0x23e2a2f74 0x23e29ba64 0x210f7c1cc 0x210f7c14c 0x210f7ba30 0x210f768fc 0x210f761cc 0x2131ed584 0x23e1b9054 0x1040a9210 0x210a36bb4)
libc++abi.dylib: terminating with uncaught exception of type NSException
I gather from this that somewhere I'm trying to access a non-existent index in an array but I've no idea where it is.
I've searched through SO for similar errors and I came across the advice to activate breakpoints when an exception is thrown. I've done that and the code seems to break immediately after the 'old' scene is deinitialised. The exception seems to be thrown in the thread immediately after [SKScene dealloc].
Here's the code that seems to be throwing the exception (which doesn't help me at all!)
deinit {
print("Game Scene deinitialised")
}
Does that mean that something is happening during deallocation that is causing the crash? I would happily post some code snippets but don't know where to start. The SKScene is quite complex.
Here's what the main thread looks like when it crashes - #17 is apparently where it all goes wrong
#0 0x00000002101bda08 in objc_exception_throw ()
#1 0x0000000210f63470 in _CFThrowFormattedException ()
#2 0x0000000210ed32ac in -[__NSArrayM removeObjectsInRange:] ()
#3 0x00000002288df1a0 in -[SKSoundSource purgeCompletedBuffers] ()
#4 0x00000002288df438 in -[SKSoundSource dealloc] ()
#5 0x00000002288b13d8 in -[SKPlaySound .cxx_destruct] ()
#6 0x00000002101bc468 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#7 0x00000002101cc70c in objc_destructInstance ()
#8 0x00000002101cc774 in object_dispose ()
#9 0x000000022880fe18 in -[SKAction dealloc] ()
#10 0x00000001046de4a4 in @objc GameScene.__ivar_destroyer ()
#11 0x00000002101bc468 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#12 0x00000002101cc70c in objc_destructInstance ()
#13 0x00000002101cc774 in object_dispose ()
#14 0x000000023e1e56cc in -[UIResponder dealloc] ()
#15 0x00000002288911e8 in -[SKNode dealloc] ()
#16 0x0000000228845c5c in -[SKScene dealloc] ()
#17 0x00000001046de400 in GameScene.__deallocating_deinit at /Users/
#18 0x00000001046de438 in @objc GameScene.__deallocating_deinit ()
#19 0x00000001047212ec in NextGameBar.touchesEnded(_:with:) at /Users/
#20 0x0000000104721390 in @objc NextGameBar.touchesEnded(_:with:) ()
#21 0x000000022886c1b0 in -[SKView touchesEnded:withEvent:] ()
#22 0x000000023e1f418c in -[UIWindow _sendTouchesForEvent:] ()
#23 0x000000023e1f53f0 in -[UIWindow sendEvent:] ()
#24 0x000000023e1d46ec in -[UIApplication sendEvent:] ()
#25 0x000000023e2a057c in __dispatchPreprocessedEventFromEventQueue ()
#26 0x000000023e2a2f74 in __handleEventQueueInternal ()
#27 0x000000023e29ba64 in __handleHIDEventFetcherDrain ()
#28 0x0000000210f7c1cc in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#29 0x0000000210f7c14c in __CFRunLoopDoSource0 ()
#30 0x0000000210f7ba30 in __CFRunLoopDoSources0 ()
#31 0x0000000210f768fc in __CFRunLoopRun ()
#32 0x0000000210f761cc in CFRunLoopRunSpecific ()
#33 0x00000002131ed584 in GSEventRunModal ()
#34 0x000000023e1b9054 in UIApplicationMain ()
#35 0x00000001047111e0 in main at /Users/
#36 0x0000000210a36bb4 in start ()
Many thanks for all assistance.