1

How is it that this code is crashing when calling tableView.reloadData() ??

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let count = self.player.queueForPlayer.count
        return count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let song: MPMediaItem = self.player.queueForPlayer.items[indexPath.row]  // EXC_BAD_ACCESS !!!
   
        ///  etc.
    }

So the queueForPlayer.items array is not mutated in this time. queueForPlayer is of type MPMediaItemCollection

The items array has 100 elements in it, and my table code crashes on IndexPath section 0, row 1.

I mean this seems to be pretty basic stuff, so all I can think of is that the MPMediaItem data type is doing something funky?

When I debug with Address Sanitizer, and try listing the .queue, it puts this in the console:

-[MPConcreteMediaItem retain]: message sent to deallocated instance 0x161ccc0d0

Because there is no public API for MPConcreteMediaItem, so I'm thinking this is why Apple doesn't expose the MPMusicPlayerController queue? I don't think we're supposed to retain MPMediaItem objects? I don't know.

UPDATE: When I stepped through slowly, and inspected other aspects of the code, it would then not crash. So I suspect I have some sort of race condition? Or Apple has one of its "pseudo-synchronous" API methods that in fact isn't?

Should i instead just store an array to persistentID values, then each time I need info about the MPMediaItem I can do (individual, ugh) media queries on them?

horseshoe7
  • 2,745
  • 2
  • 35
  • 49
  • I think that managing all access to .items inside a concurrent dispatch queue with Barrier might solve it – Arik Segal Sep 21 '20 at 08:49
  • what's Barrier? Maybe the large B threw me off, thinking this is some sort of product. Instead of just randomly trying that, have you got any insights into why the above is happening? I mean I have an that is not mutated, supposedly retaining MPMediaItem objects... – horseshoe7 Sep 21 '20 at 08:54

0 Answers0