Bug 1568 - Random crashes at startup when debugging
Summary: Random crashes at startup when debugging
Status: RESOLVED DUPLICATE of bug 707
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Other Other
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-10-19 07:30 UTC by Jamie Briant
Modified: 2011-10-20 08:22 UTC (History)
2 users (show)

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

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 DUPLICATE of bug 707

Description Jamie Briant 2011-10-19 07:30:51 UTC
Before I call UIApplication.Main I do some set-up. However, I have a recurring problem where the app throws a NullReferenceException.

Currently this is happening on my 3GS running iOS 5. It has happened before on my iPod Touch 4 running 4.3. Right now, its not happening on my iPod however.




Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Moonfruit starting
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>:   at BinaryFinery.Touch.Threading.DummyThread..ctor () [0x00000] in <filename unknown>:0 
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>:   at BinaryFinery.Touch.Threading.DummyThread..ctor () [0x00000] in <filename unknown>:0 
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Terminating runtime due to unhandled exception
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Stacktrace:
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Native stacktrace:
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	0   Moonfruit                           0x005ebca0 mono_handle_native_sigsegv + 456
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	1   Moonfruit                           0x0061934c sigabrt_signal_handler + 168
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	2   libsystem_c.dylib                   0x33b32539 _sigtramp + 48
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	3   libsystem_c.dylib                   0x33b27f5b pthread_kill + 54
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	4   libsystem_c.dylib                   0x33b20feb abort + 94
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	5   Moonfruit                           0x00768fd4 monoeg_g_logv + 268
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	6   Moonfruit                           0x007690a8 monoeg_assertion_message + 80
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	7   Moonfruit                           0x005bf7e0 mono_thread_abort + 220
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	8   Moonfruit                           0x005ea474 mono_handle_exception_internal + 2572
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	9   Moonfruit                           0x005eb21c mono_handle_exception + 120
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	10  Moonfruit                           0x00618244 handle_signal_exception + 140
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	11  ???                                 0xe59b1028 0x0 + 3852144680
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	12  Moonfruit                           0x0051df90 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	13  Moonfruit                           0x005c4510 mono_jit_runtime_invoke + 2892
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	14  Moonfruit                           0x006d7a9c mono_runtime_invoke + 200
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	15  Moonfruit                           0x006dacbc mono_runtime_exec_main + 836
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	16  Moonfruit                           0x006d9c88 mono_runtime_run_main + 968
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	17  Moonfruit                           0x005cf47c mono_jit_exec + 244
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	18  Moonfruit                           0x005ba464 main + 3948
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: 	19  Moonfruit                           0x00002c70 start + 40
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: =================================================================
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: Got a SIGABRT while executing native code. This usually indicates
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: a fatal error in the mono runtime or one of the native libraries 
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: used by your application.
Oct 19 03:53:45 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xd305][441] <Notice>: =================================================================
Comment 1 Jamie Briant 2011-10-19 07:35:40 UTC
    [Register("DummyThread")]
    public class DummyThread : NSObject
    {
        [Export("myMainThreadMethod:")]
        [Preserve]
        public void ThreadMain(NSObject what)
        {
        }
    }


    private static void Main(string[] args)
    {
        dummy = new DummyThread();
...
Comment 2 Jamie Briant 2011-10-19 07:44:40 UTC
If instead I have this code:

        private static void Main(string[] args)
        {
            CocoaThreads.Initialize();
...

Then I get this crash:

Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>:   at BinaryFinery.Touch.Threading.CocoaThreads.Initialize () [0x00000] in <filename unknown>:0 
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>:   at BinaryFinery.Touch.Threading.CocoaThreads.Initialize () [0x00000] in <filename unknown>:0 
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: Terminating runtime due to unhandled exception
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: Stacktrace:
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: Native stacktrace:
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	0   Moonfruit                           0x005eaca0 mono_handle_native_sigsegv + 456
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	1   Moonfruit                           0x0061834c sigabrt_signal_handler + 168
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	2   libsystem_c.dylib                   0x33b32539 _sigtramp + 48
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	3   libsystem_c.dylib                   0x33b27f5b pthread_kill + 54
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	4   libsystem_c.dylib                   0x33b20feb abort + 94
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	5   Moonfruit                           0x00767fd4 monoeg_g_logv + 268
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	6   Moonfruit                           0x007680a8 monoeg_assertion_message + 80
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	7   Moonfruit                           0x005be7e0 mono_thread_abort + 220
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	8   Moonfruit                           0x005e9474 mono_handle_exception_internal + 2572
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	9   Moonfruit                           0x005ea21c mono_handle_exception + 120
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	10  Moonfruit                           0x00617244 handle_signal_exception + 140
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	11  ???                                 0xe59be004 0x0 + 3852197892
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	12  Moonfruit                           0x0051cf90 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	13  Moonfruit                           0x005c3510 mono_jit_runtime_invoke + 2892
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	14  Moonfruit                           0x006d6a9c mono_runtime_invoke + 200
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	15  Moonfruit                           0x006d9cbc mono_runtime_exec_main + 836
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	16  Moonfruit                           0x006d8c88 mono_runtime_run_main + 968
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	17  Moonfruit                           0x005ce47c mono_jit_exec + 244
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	18  Moonfruit                           0x005b9464 main + 3948
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: 	19  Moonfruit                           0x00002400 start + 40
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: =================================================================
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: Got a SIGABRT while executing native code. This usually indicates
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: a fatal error in the mono runtime or one of the native libraries 
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: used by your application.
Oct 19 04:43:29 unknown UIKitApplication:com.moonfruit.apps.Moonfruit[0xb9aa][653] <Notice>: =================================================================
Comment 3 Rolf Bjarne Kvinge [MSFT] 2011-10-19 07:50:08 UTC
Are the NullReferenceExceptions random or do they happen every time you start your app? And can you reproduce using just the code you pasted above?
Comment 4 Jamie Briant 2011-10-19 08:04:13 UTC
For any given set of code, it either works 100% or fails 100%. However, if I change one line of code, it might start working (or failing).

I cannot make a test case that fails. I could perhaps send you my entire project. Or even give you git access perhaps.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2011-10-19 08:06:33 UTC
Yeah, a test case would make it much simpler to fix - if it happens on any of our devices of course. You can add private attachments (which only Xamarin employees can see).
Comment 6 Jamie Briant 2011-10-19 08:36:21 UTC
so in manually deleting all the bin/obj directories so the zip wouldn't be 150mb, the bug has gone again. if it comes up again i will drop box the whole bloody thing.
Comment 7 Jamie Briant 2011-10-19 08:46:38 UTC
This is staggeringly frustrating. I lost about four hours to this today. I have a deadline friday. 20 minutes to just trying to make a copy of the entire build i can send you only to have moving the bloody files make the bug go away. I need to be able to debug this myself, and to do that I need native debugging. In Visual Studio I can debug native and C#. How can I do this in MT???
Comment 8 Jamie Briant 2011-10-19 20:40:51 UTC
Ok, I uploaded a complete set of files to dropbox and sent an invite to rolf.
Comment 9 Rolf Bjarne Kvinge [MSFT] 2011-10-19 21:28:12 UTC
I can reproduce "Random crashes at startup.", I'll have a better look tomorrow.
Comment 10 Rolf Bjarne Kvinge [MSFT] 2011-10-20 04:53:04 UTC
It looks like the native binary you're linking with is tripping up MonoTouch somehow (there are known issues when native libraries are compiled for thumb for instance). I applied the test described here: http://lists.ximian.com/pipermail/monotouch/2011-September/005393.html to check for thumb instructions on libBinaryFineryNative.a, and it came back positive. 

It is quite easy to reproduce issues with the native library: I removed all source files (with just a Console.WriteLine in the Main method), set linker behavior to "Don't link" and in additional mtouch args only left the arguments to link with the native library. Now it will crash every time you run on device.

I suggest you try compiling different versions of your library to see what works (in theory gcc+nothumbs should work, you might want to try not making universal binaries too, even though that shouldn't make a difference).
Comment 11 Jamie Briant 2011-10-20 05:07:22 UTC
That's an awesome discovery. I will sort that out immediately. Two questions:

1. How did you figure it out? (so that I may diagnose such problems myself in future)

2. How come it crashes before any of the native code is called? Is it a linker issue?

thx.
Comment 12 Rolf Bjarne Kvinge [MSFT] 2011-10-20 05:26:03 UTC
1) By commenting out code until there was no code left. Changing linker options also tend to make bugs manifest themselves differently (and by not linking you're also doing less when going from source->final binary, so it's one more thing you're excluding). In this case disabling the linker caused a 100% reproducible crash (not the same as you were having initially, but it may very well be related), and reproducible crashes are always easier to track down.

2) Yes, there is a bug in Apple's linker: http://docs.xamarin.com/ios/troubleshooting#Assertion_at_...2f...2f...2f...2fmono.2fmetadata.2fgeneric-sharing.c.3a704.2c_condition_.60oti'_not_met
Comment 13 Rolf Bjarne Kvinge [MSFT] 2011-10-20 08:22:22 UTC
Marking as duplicate of 707.

*** This bug has been marked as a duplicate of bug 707 ***