herzbube / littlego

Little Go. An iOS application that lets you play the game of Go on the iPhone or iPad.
https://littlego.herzbube.ch/
Apache License 2.0
138 stars 54 forks source link

App crash when traitCollectionDidChange is invoked too early for BoardPositionCollectionViewCell #397

Closed herzbube closed 1 year ago

herzbube commented 1 year ago

Received multiple crash reports via Firebase/Crashlytics on day 1 after the release of 1.7.0.

Crash report indicates the following:

herzbube commented 1 year ago

The line indication is clearly wrong, as there is no call to the NSArray method objectAtIndex: at line 485. However if we dive deeper into what does happen on line 485 we see that the objectAtIndex: method is eventually invoked within GoNodeModel.m, in method nodeAtIndex:.

The only way how this can happen is if a cell gets reused and still has its old value for the boardPosition property, while UIKit also decides that it needs to invoke traitCollectionDidChange:. If the cell reuse occurs e.g. after a new game was started, or after some board positions were discarded, then the boardPosition property value may easily be invalid now.

The issue cannot be reproduced easily because cell reuse is not under our control.