Bug 16503 - MPNowPlaying
Summary: MPNowPlaying
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.6.x
Hardware: PC Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-11-28 20:05 UTC by James Clancey
Modified: 2014-01-13 13:18 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
testcase (67 bytes, text/plain)
2013-12-17 21:46 UTC, James Clancey
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description James Clancey 2013-11-28 20:05:14 UTC
There is a bug with MPNowPlayingInfo.  My app is regularly crashing while setting the Default center; I have the code in a try catch but since this is happening in native land it isn't catching.

Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>: Stacktrace:
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at <unknown> <0xffffffff>
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr (intptr,intptr,intptr,intptr) <0xffffffff>
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at MonoTouch.Foundation.NSMutableDictionary.SetObject (MonoTouch.Foundation.NSObject,MonoTouch.Foundation.NSObject) <0x00057>
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at MonoTouch.Foundation.NSMutableDictionary.Add (MonoTouch.Foundation.NSObject,MonoTouch.Foundation.NSObject) <0x00037>
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at MonoTouch.MediaPlayer.MPNowPlayingInfo.ToDictionary () <0x0051f>
Nov 27 22:45:59 Clanceys-iPhone-5S SmartEq[1552] <Error>:   at MonoTouch.MediaPlayer.MPNowPlayingInfoCenter.set_NowPlaying
Comment 1 Sebastien Pouliot 2013-11-29 08:50:35 UTC
We need:

* a test case to reproduce the issue;
* the device crash report;
* to know the software versions you're using [1]


[1] The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 James Clancey 2013-12-17 21:46:42 UTC
Created attachment 5685 [details]
testcase
Comment 3 James Clancey 2013-12-17 21:50:39 UTC
Here is a small testcase.  Its hard to duplicate exactly, but this code eventually should blow up. Just let it run on device.
Comment 4 Sebastien Pouliot 2013-12-17 22:15:58 UTC
2013-12-17 21:59:22.591 MPNowPlayingInfoCrash[4584:60b] Application windows are expected to have a root view controller at the end of application launch
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
2013-12-17 21:59:23.093 MPNowPlayingInfoCrash[4584:9603] Time Updated
2013-12-17 21:59:24.554 MPNowPlayingInfoCrash[4584:9603] Time Updated
2013-12-17 21:59:25.559 MPNowPlayingInfoCrash[4584:9603] Time Updated
2013-12-17 21:59:26.555 MPNowPlayingInfoCrash[4584:9603] Time Updated
2013-12-17 21:59:27.554 MPNowPlayingInfoCrash[4584:9603] Time Updated
2013-12-17 21:59:27.600 MPNowPlayingInfoCrash[4584:9603] Artwork Updated
2013-12-17 21:59:27.604 MPNowPlayingInfoCrash[4584:9603] Is playing: True
2013-12-17 21:59:28.555 MPNowPlayingInfoCrash[4584:9603] Time Updated

...

2013-12-17 22:04:47.707 MPNowPlayingInfoCrash[4584:9603] MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** setObjectForKey: object cannot be nil (key: discCount)
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_IntPtr (intptr,intptr,intptr,intptr)
  at MonoTouch.Foundation.NSMutableDictionary.SetObject (MonoTouch.Foundation.NSObject obj, MonoTouch.Foundation.NSObject key) [0x00025] in /Developer/MonoTouch/Source/monotouch/src/build/compat/Foundation/.pmcs-compat.NSMutableDictionary.g.cs:248 
  at MonoTouch.Foundation.NSMutableDictionary.Add (MonoTouch.Foundation.NSObject key, MonoTouch.Foundation.NSObject value) [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/.pmcs-compat.NSMutableDictionary.cs:266 
  at MonoTouch.MediaPlayer.MPNowPlayingInfo.ToDictionary () [0x0016e] in /Developer/MonoTouch/Source/monotouch/src/MediaPlayer/.pmcs-compat.MPNowPlayingInfoCenter.cs:59 
  at MonoTouch.MediaPlayer.MPNowPlayingInfoCenter.set_NowPlaying (MonoTouch.MediaPlayer.MPNowPlayingInfo value) [0x00012] in /Developer/MonoTouch/Source/monotouch/src/MediaPlayer/.pmcs-compat.MPNowPlayingInfoCenter.cs:140 
  at MPNowPlayingInfoCrash.AppDelegate.UpdateNowPlayingArtwork (MonoTouch.UIKit.UIImage image) [0x0003a] in /Users/poupou/Downloads/MPNowPlayingInfoCrash/MPNowPlayingInfoCrash/AppDelegate.cs:109 
NSInvalidArgumentException: *** setObjectForKey: object cannot be nil (key: discCount)
	0   CoreFoundation                      0x3012ff6b <redacted> + 154
	1   libobjc.A.dylib                     0x3a8366af objc_exception_throw + 38
	2   CoreFoundation                      0x3006b727 <redacted> + 818
	3   MPNowPlayingInfoCrash               0x00085e5c wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_IntPtr_IntPtr_intptr_intptr_intptr_intptr + 116
	4   MPNowPlayingInfoCrash               0x0006c3f0 MonoTouch_Foundation_NSMutableDictionary_SetObject_MonoTouch_Foundation_NSObject_MonoTouch_Foundation_NSObject + 88
	5   MPNowPlayingInfoCrash               0x0006c098 MonoTouch_Foundation_NSMutableDictionary_Add_MonoTouch_Foundation_NSObject_MonoTouch_Foundation_NSObject + 56
	6   MPNowPlayingInfoCrash               0x000792c8 MonoTouch_MediaPlayer_MPNowPlayingInfo_ToDictionary + 1312
	7   MPNowPlayingInfoCrash               0x00079690 MonoTouch_MediaPlayer_MPNowPlayingInfoCenter_set_NowPlaying_MonoTouch_MediaPlayer_MPNowPlayingInfo + 68
	8   MPNowPlayingInfoCrash               0x000681f8 MPNowPlayingInfoCrash_AppDelegate_UpdateNowPlayingArtwork_MonoTouch_UIKit_UIImage + 408
	9   MPNowPlayingInfoCrash               0x00068b00 MPNowPlayingInfoCrash_AppDelegate__FinishedLaunchingm__1_object_System_Timers_ElapsedEventArgs + 304
	10  MPNowPlayingInfoCrash               0x0014a930 System_Timers_Timer_Callback_object + 448
	11  MPNowPlayingInfoCrash               0x000bc628 System_Threading_Timer_Scheduler_TimerCB_object + 104
	12  MPNowPlayingInfoCrash               0x0011eb70 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
	13  MPNowPlayingInfoCrash               0x0017815b mono_jit_runtime_invoke + 1138
	14  MPNowPlayingInfoCrash               0x001b1325 mono_runtime_invoke + 88
	15  MPNowPlayingInfoCrash               0x001b4a5b mono_runtime_delegate_invoke + 62
	16  MPNowPlayingInfoCrash               0x001bd661 async_invoke_thread + 2324
	17  MPNowPlayingInfoCrash               0x001bf3fd start_wrapper + 232
	18  MPNowPlayingInfoCrash               0x001ccde7 thread_start_routine + 106
	19  MPNowPlayingInfoCrash               0x001d38e1 inner_start_thread + 44
	20  MPNowPlayingInfoCrash               0x001e0b3b GC_start_routine + 54
	21  libsystem_pthread.dylib             0x3ae5dc1d <redacted> + 140
	22  libsystem_pthread.dylib             0x3ae5db8f _pthread_start + 102
	23  libsystem_pthread.dylib             0x3ae5bc90 thread_start + 8

... 5 minutes later ...

Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Warning>: Is playing: True
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: Stacktrace:
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at <unknown> <0xffffffff>
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr (intptr,intptr,intptr,intptr) <0xffffffff>
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MonoTouch.Foundation.NSMutableDictionary.SetObject (MonoTouch.Foundation.NSObject,MonoTouch.Foundation.NSObject) [0x00025] in /Developer/MonoTouch/Source/monotouch/src/build/compat/Foundation/.pmcs-compat.NSMutableDictionary.g.cs:248
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MonoTouch.Foundation.NSMutableDictionary.Add (MonoTouch.Foundation.NSObject,MonoTouch.Foundation.NSObject) [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/.pmcs-compat.NSMutableDictionary.cs:266
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MonoTouch.MediaPlayer.MPNowPlayingInfo.ToDictionary () [0x00143] in /Developer/MonoTouch/Source/monotouch/src/MediaPlayer/.pmcs-compat.MPNowPlayingInfoCenter.cs:57
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MonoTouch.MediaPlayer.MPNowPlayingInfoCenter.set_NowPlaying (MonoTouch.MediaPlayer.MPNowPlayingInfo) [0x00012] in /Developer/MonoTouch/Source/monotouch/src/MediaPlayer/.pmcs-compat.MPNowPlayingInfoCenter.cs:140
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MPNowPlayingInfoCrash.AppDelegate.UpdateTime () [0x00099] in /Users/poupou/Downloads/MPNowPlayingInfoCrash/MPNowPlayingInfoCrash/AppDelegate.cs:133
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at MPNowPlayingInfoCrash.AppDelegate.<FinishedLaunching>m__0 (object,System.Timers.ElapsedEventArgs) [0x00002] in /Users/poupou/Downloads/MPNowPlayingInfoCrash/MPNowPlayingInfoCrash/AppDelegate.cs:42
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at System.Timers.Timer.Callback (object) [0x00079] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Timers/Timer.cs:189
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at System.Threading.Timer/Scheduler.TimerCB (object) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/Timer.cs:317
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 
	Native stacktrace:
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	0   MPNowPlayingInfoCrash               0x0016cff5 mono_handle_native_sigsegv + 260
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	1   MPNowPlayingInfoCrash               0x00176079 mono_sigsegv_signal_handler + 176
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	2   libsystem_platform.dylib            0x3ae59063 _sigtramp + 42
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	3   libunwind.dylib                     0x3ae66c67 _Unwind_SjLj_RaiseException + 62
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	4   libc++abi.dylib                     0x3a0eaa0f __cxa_throw + 102
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	5   libobjc.A.dylib                     0x3a836783 objc_exception_throw + 250
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	6   CoreFoundation                      0x3006b727 <redacted> + 818
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	7   MPNowPlayingInfoCrash               0x00085e5c wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_IntPtr_IntPtr_intptr_intptr_intptr_intptr + 116
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	8   MPNowPlayingInfoCrash               0x0006c3f0 MonoTouch_Foundation_NSMutableDictionary_SetObject_MonoTouch_Foundation_NSObject_MonoTouch_Foundation_NSObject + 88
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	9   MPNowPlayingInfoCrash               0x0006c098 MonoTouch_Foundation_NSMutableDictionary_Add_MonoTouch_Foundation_NSObject_MonoTouch_Foundation_NSObject + 56
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	10  MPNowPlayingInfoCrash               0x00079240 MonoTouch_MediaPlayer_MPNowPlayingInfo_ToDictionary + 1176
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	11  MPNowPlayingInfoCrash               0x00079690 MonoTouch_MediaPlayer_MPNowPlayingInfoCenter_set_NowPlaying_MonoTouch_MediaPlayer_MPNowPlayingInfo + 68
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	12  MPNowPlayingInfoCrash               0x000687f4 MPNowPlayingInfoCrash_AppDelegate_UpdateTime + 1080
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	13  MPNowPlayingInfoCrash               0x000689a4 MPNowPlayingInfoCrash_AppDelegate__FinishedLaunchingm__0_object_System_Timers_ElapsedEventArgs + 148
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	14  MPNowPlayingInfoCrash               0x0014a930 System_Timers_Timer_Callback_object + 448
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	15  MPNowPlayingInfoCrash               0x000bc628 System_Threading_Timer_Scheduler_TimerCB_object + 104
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	16  MPNowPlayingInfoCrash               0x0011eb70 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	17  MPNowPlayingInfoCrash               0x0017815b mono_jit_runtime_invoke + 1138
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	18  MPNowPlayingInfoCrash               0x001b1325 mono_runtime_invoke + 88
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	19  MPNowPlayingInfoCrash               0x001b4a5b mono_runtime_delegate_invoke + 62
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	20  MPNowPlayingInfoCrash               0x001bd661 async_invoke_thread + 2324
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	21  MPNowPlayingInfoCrash               0x001bf3fd start_wrapper + 232
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	22  MPNowPlayingInfoCrash               0x001ccde7 thread_start_routine + 106
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	23  MPNowPlayingInfoCrash               0x001d38e1 inner_start_thread + 44
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	24  MPNowPlayingInfoCrash               0x001e0b3b GC_start_routine + 54
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	25  libsystem_pthread.dylib             0x3ae5dc1d <redacted> + 140
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	26  libsystem_pthread.dylib             0x3ae5db8f _pthread_start + 102
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 	27  libsystem_pthread.dylib             0x3ae5bc90 thread_start + 8
Dec 17 22:12:32 Jupiter MPNowPlayingInfoCrash[4584] <Error>: 
	=================================================================
	Got a SIGSEGV while executing native code. This usually indicates
	a fatal error in the mono runtime or one of the native libraries 
	used by your application.
	=================================================================

Takes a bit of time but it eventually crash - but not always (see exception).
Comment 5 James Clancey 2013-12-17 22:18:42 UTC
Awesome, This is the only crash report I am getting for my new app!
Comment 6 Sebastien Pouliot 2013-12-17 23:56:51 UTC
Quick guess before going to sleep:

	MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;

is called from 3 places. Two of them are called several times (the other being called only once) on different threads.

Apple documentation is really bad on thread safety. Some other MediaPlayer types, e.g. MPMusicPlayerController, are clearly documented as:

> Important: You must use a music player only on your app’s main thread.

but most lack any safe/unsafe guidance.

OTOH the crash report does not seems to show two threads accessing MP code. This _might_ be because something got corrupted earlier (e.g. the exception that did not crash). I'll test that tomorrow.
Comment 7 James Clancey 2013-12-18 00:21:00 UTC
All of it works from the background thread. If you lock your phone you will watch the time update and the Artwork change every 5 seconds. But a mid air collision of the same object would make sense.
Comment 8 Sebastien Pouliot 2013-12-18 11:16:45 UTC
> All of it works from the background thread.

Maybe but this is always the wrong answer. We're talking about thread *safety* here. A lot of things _seems_ to work (and do work 99.9% of the time) on a different thread - but it does not mean it's safe to do so [1].

[1] http://www.youtube.com/watch?v=wZpD3Iuc05k <- it works but it's not safe

Most of UIKit "seems to works" on background too - but we stopped getting weird, random, unreproducible crashes when we disallowed them (by default) outside the main thread.


I cannot duplicate the issue (it's been running for an hour now) when I add some C.WL - and that might just be it makes it less likely to happen simultaneously.

2013-12-18 10:12:21.558 MPNowPlayingInfoCrash[4682:60b] >SharedOnCurrentSongChanged
2013-12-18 10:12:21.594 MPNowPlayingInfoCrash[4682:60b] <SharedOnCurrentSongChanged
Thread started:  #3
2013-12-18 10:12:21.635 MPNowPlayingInfoCrash[4682:60b] Application windows are expected to have a root view controller at the end of application launch
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
2013-12-18 10:12:22.615 MPNowPlayingInfoCrash[4682:9603] > UpdateTime
2013-12-18 10:12:22.622 MPNowPlayingInfoCrash[4682:9603] < UpdateTime
...
2013-12-18 11:12:00.277 MPNowPlayingInfoCrash[4682:9603] > UpdateTime
2013-12-18 11:12:00.284 MPNowPlayingInfoCrash[4682:9603] < UpdateTime
2013-12-18 11:12:01.277 MPNowPlayingInfoCrash[4682:9603] > UpdateTime
2013-12-18 11:12:01.284 MPNowPlayingInfoCrash[4682:9603] < UpdateTime
2013-12-18 11:12:01.714 MPNowPlayingInfoCrash[4682:9603] >UpdateNowPlayingArtwork
2013-12-18 11:12:01.721 MPNowPlayingInfoCrash[4682:9603] <UpdateNowPlayingArtwork True


I'll let it run a while longer (up to after lunch) and remove them (and add a lock around it).
Comment 9 Sebastien Pouliot 2013-12-18 13:02:26 UTC
Stopped at:

2013-12-18 13:01:06.479 MPNowPlayingInfoCrash[4682:9603] > UpdateTime
2013-12-18 13:01:06.483 MPNowPlayingInfoCrash[4682:9603] 	>d 384281440 1
2013-12-18 13:01:06.484 MPNowPlayingInfoCrash[4682:9603] 	<d 384281440 2
2013-12-18 13:01:06.486 MPNowPlayingInfoCrash[4682:9603] < UpdateTime
2013-12-18 13:01:06.850 MPNowPlayingInfoCrash[4682:9603] >UpdateNowPlayingArtwork
2013-12-18 13:01:06.856 MPNowPlayingInfoCrash[4682:9603] 	>d 383343696 1
2013-12-18 13:01:06.859 MPNowPlayingInfoCrash[4682:9603] 	<d 383343696 2
2013-12-18 13:01:06.860 MPNowPlayingInfoCrash[4682:9603] <UpdateNowPlayingArtwork True

That's nearly 3 hours without a crash (or an exception since I removed the try/catch from the sample).
Comment 10 Sebastien Pouliot 2013-12-18 21:48:20 UTC
The above "worked" (adding C.WL) but adding locks did not. It crashed about 20-30 minutes later.

Worse I could reproduce the same crash when I commented the timer on UpdateNowPlayingArtwork. That means the issue is not (totally at least) related to simultaneous access.

Going back to my original idea: it must be done on the main thread.

* That worked for 2 hours (I stopped it) for only UpdateTime;
* That's still working with both timers (been running for nearly 3 hours).

You might want to try that and report back if you get crash reports.

I'll likely restart it tomorrow, same code but without the C.WL, to be 100% sure.
Comment 11 Sebastien Pouliot 2013-12-19 10:09:11 UTC
...
Dec 19 10:07:51 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: < UpdateTime
Dec 19 10:07:51 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: > UpdateNowPlayingArtwork
Dec 19 10:07:51 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: < UpdateNowPlayingArtwork True 1 1
Dec 19 10:07:52 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: > UpdateTime 54787.025284
Dec 19 10:07:52 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: < UpdateTime
Dec 19 10:07:53 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: > UpdateTime 54788.025376
Dec 19 10:07:53 Jupiter MPNowPlayingInfoCrash[4915] <Warning>: < UpdateTime

That's more than 15 hours without a crash. I'm stopping it to test without the C.WL.
Comment 12 James Clancey 2013-12-19 14:15:08 UTC
I have switched the final 
MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo
to fire on the main thread. I will test and see if that fixes it for me.
Comment 13 Sebastien Pouliot 2013-12-19 17:33:00 UTC
I'll keep it running tonight - it's been running fine for 6.5 hours now. That's the version where there is:

* no try/catch

* no Console.WriteLine

* no locks

* setting NowPlaying is always done on the main thread

	InvokeOnMainThread (delegate {
		MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;
	});
Comment 14 James Clancey 2013-12-19 17:39:14 UTC
Is it possible to get our try catch to pick up that exception? Or no because its in native land?
Comment 15 Rolf Bjarne Kvinge [MSFT] 2013-12-19 19:25:38 UTC
No, it's not possible handle crashes in managed code. And in any case it would be a bad idea to hide the underlying race condition with a try-catch, since you still have the race condition, now it'll just be harder to reproduce (most likely it'll crash somewhere else).
Comment 16 Sebastien Pouliot 2013-12-20 11:05:18 UTC
It's been running for over 24 hours now. I'll stop it since I need the device for other stuff ;-)

@James, it can some time be catched* by a try/catch, but it's uncommon and the stack might corrupted. So, life Rolf said, it's better to crash in a way that will be easy to debug than to hide the clue that could prove useful (in the crash report produce later).

* the logs above shows that it was once before the crash that killed the app.
Comment 17 Sebastien Pouliot 2014-01-13 09:39:36 UTC
James, did running on the main thread worked out for your app ? if so please close the bug.
Comment 18 James Clancey 2014-01-13 13:17:43 UTC
I have been checking crash reports, so far so good!
Comment 19 James Clancey 2014-01-13 13:18:25 UTC
Fixed