title: Random crash in AVPlayer on TrampolineAVCompletionHandle / max number of trampolines
body: <p>I have a crash that sometimes occurs in my app when using the AVFoundation.AVPlayer. It's happening randomly, e. g. when the user changes the position of the video or play / pause the video. I don't know how to fix it since the crash seems to occur in the MonoTouch layer.</p>
  
  <p>You can see the crash log below.</p>
  
  <p>First, what does mean: <code>System.ArgumentException: GCHandle value belongs to a different domain</code>? I tried to Google it, but I have found nothing helpful.</p>
  
  <p>Also, the line <code>MonoTouch_AVFoundation_AVPlayer_TrampolineAVCompletionHandler</code> maybe indicates that I have a problem with the number of trampolines I have set in the build settings:</p>
  
  <p>-aot "ntrampolines=4048" "nimt-trampolines=4048"</p>
  
  <p>Maybe I should increase this number, but someone know what is the limit we can set? and what are the consequences if I increase this number? performance / memory issues?</p>
  
  <pre><code>[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: GCHandle value belongs to a different domain
    at System.Runtime.InteropServices.GCHandle.op_Explicit (IntPtr value) [0x00036] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:126 
    at System.Runtime.InteropServices.GCHandle.FromIntPtr (IntPtr value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:169 
    at MonoTouch.AVFoundation.AVPlayer.TrampolineAVCompletionHandler (IntPtr block) [0x00007] in /Developer/MonoTouch/Source/monotouch/src/AVFoundation/AVPlayer.g.cs:501 
    at (wrapper native-to-managed) MonoTouch.AVFoundation.AVPlayer:TrampolineAVCompletionHandler (intptr)
    at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
    at Dartfish.Application.EasyCapture.Common.Application.Main (System.String[] args) [0x00000] in /Users/admin/Dev/Dartfish/Dartfish EasyCapture/Source/Application/EasyCaptureMonoTouch/Main.cs:17 
    Symbol file /private/var/mobile/Applications/A0243AD3-C734-41E1-981E-A1ACB2E1AB77/EasyCaptureMonoTouch.app/Dartfish.LibraryCoreHeimdall.dll.mdb doesn't match image /private/var/mobile/Applications/A0243AD3-C734-41E1-981E-A1ACB2E1AB77/EasyCaptureMonoTouch.app/Dartfish.LibraryCoreHeimdall.dll
    Terminating runtime due to unhandled exception
  Stacktrace:
  
  
  Native stacktrace:
  
  0   MonoTouchEasyCapture                0x0187e451 mono_handle_native_sigsegv + 244
  1   MonoTouchEasyCapture                0x01895501 sigabrt_signal_handler + 112
  2   libsystem_c.dylib                   0x328ba7ed _sigtramp + 48
  3   libsystem_c.dylib                   0x328b020f pthread_kill + 54
  4   libsystem_c.dylib                   0x328a929f abort + 94
  5   MonoTouchEasyCapture                0x0192cb5d monoeg_assertion_message + 0
  6   MonoTouchEasyCapture                0x0192cb7f monoeg_assertion_message + 34
  7   MonoTouchEasyCapture                0x0186ef95 mono_thread_abort + 112
  8   MonoTouchEasyCapture                0x0187e1cf mono_handle_exception_internal + 2138
  9   MonoTouchEasyCapture                0x0187e29d mono_handle_exception + 12
  10  MonoTouchEasyCapture                0x018947c5 mono_arm_throw_exception + 116
  11  MonoTouchEasyCapture                0x01072cc4 throw_exception + 48
  12  MonoTouchEasyCapture                0x00f87cc8 System_Runtime_InteropServices_GCHandle_FromIntPtr_intptr + 36
  13  MonoTouchEasyCapture                0x00513c30 MonoTouch_AVFoundation_AVPlayer_TrampolineAVCompletionHandler_intptr + 96
  14  MonoTouchEasyCapture                0x0056e360 wrapper_native_to_managed_MonoTouch_AVFoundation_AVPlayer_TrampolineAVCompletionHandler_intptr + 64
  15  AVFoundation                        0x35303a51 __avplayeritem_fpItemNotificationCallback_block_invoke_0 + 3936
  16  libdispatch.dylib                   0x3433bc59 _dispatch_call_block_and_release + 12
  17  libdispatch.dylib                   0x3433dee7 _dispatch_main_queue_callback_4CF$VARIANT$mp + 194
  18  CoreFoundation                      0x354812ad __CFRunLoopRun + 1268
  19  CoreFoundation                      0x354044a5 CFRunLoopRunSpecific + 300
  20  CoreFoundation                      0x3540436d CFRunLoopRunInMode + 104
  21  GraphicsServices                    0x370a0439 GSEventRunModal + 136
  22  UIKit                               0x32f10cd5 UIApplicationMain + 1080
  23  MonoTouchEasyCapture                0x0056dcec wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
  24  MonoTouchEasyCapture                0x011d23d0 Dartfish_Application_EasyCapture_Common_Application_Main_string__ + 152
  25  MonoTouchEasyCapture                0x0103ab08 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
  26  MonoTouchEasyCapture                0x01870d57 mono_jit_runtime_invoke + 1054
  27  MonoTouchEasyCapture                0x018e0abb mono_runtime_invoke + 90
  28  MonoTouchEasyCapture                0x018e37f7 mono_runtime_exec_main + 306
  29  MonoTouchEasyCapture                0x018e3a4b mono_runtime_run_main + 482
  30  MonoTouchEasyCapture                0x01873dbf mono_jit_exec + 94
  31  MonoTouchEasyCapture                0x0186e59b main + 2802
  32  MonoTouchEasyCapture                0x000029c8 start + 40
  </code></pre>