xbmc / Official-Kodi-Remote-iOS

Full-featured remote control for XBMC Media Center. It features library browsing, now playing informations and a direct remote control.
Other
222 stars 104 forks source link

Avoid crash updateChannelListTableCell #682

Closed wutschel closed 2 years ago

wutschel commented 2 years ago

From a comment by @kambala-decapitator it is per documentation not allowed to call reloadData between beginUpdates/endUpdate. In the App's code this might happen when the worker thread which updates the information for the visible channels is concurring with the updates trigger from the main thread. Choices to fix this is either using dispatch_sync to serialize any such event, or simply using reloadData. The latter will not only update the visible entries of the channel list, but all of them.

The reloadData solution (https://github.com/xbmc/Official-Kodi-Remote-iOS/compare/master...wutschel:fix_channelupdate):

The dispatch_sync solution would require each reloadData call inside DetailViewController to be encapsulated with dispatch_sync. In this case I would introduce helper methods for this.

kambala-decapitator commented 2 years ago

reloadData must be called only from the main thread

wutschel commented 2 years ago

I need to correct myself. The function which possibly concurs is called via a timer. Is a timer spawning a worker thread well?

kambala-decapitator commented 2 years ago

Timer callback is called on the thread which you schedule the timer on

wutschel commented 2 years ago

Thanks, then this is main thread.

wutschel commented 2 years ago

Do I still need to use dispatch_sync to avoid that beginUpdates / endUpdates is interrupted by reloadData when all calls come from the main thread?

kambala-decapitator commented 2 years ago

Do I still need to use dispatch_sync to avoid that beginUpdates / endUpdates is interrupted by reloadData when all calls come from the main thread?

sorry, missed your question. If you attempt to execute

dispatch_sync(dispatch_get_main_queue(), ^{ ... });

on main thread, you'll get into deadlock.