I would truly appreciate some feedback on my approach above. At first, it seemed to reduce the number of crashes. Now I would like to use it in more places in my code to hopefully reduce the number of crashes even further... but instead I get another crash that I'm able to reproduce about 50% of the times I launch my game.
The crash happens at the line
skQueue.updates.append(block) // crash: Thread 9: signal SIGABRT
The Xcode console prints the following warning twice:
Object 0xc1b5c9e00 of class _ContiguousArrayStorage deallocated with non-zero retain count 2. This object's deinit, or something called from it, may have created a strong reference to self which outlived deinit, resulting in a dangling reference.
If I show the Memory Graph, search for the address 0xc1b5c9e00 in the Debug Navigator and select the search result, the Memory Graph seems to confirm that the address is in fact some private storage belonging to the skQueue.updates array.
How could this crash happen, if skQueue.updates is only ever modified in those two places shown in the code above, both of which are run in a queue , as far as I know, sequentially?