Mecanim causing Unity crash - unhandled NULL exception (using latest 4.1.2)

HI there,

I’m in the process of submitting a bug report, the file is taking a while to upload. In the meantime I thought I’d post a similar message to the forums and see if anyone else has any ideas:

1) What happened

We continually receive an exception: Receiving unhandled NULL exception, which can only be read in the Console log (Mac OSX), we’ve been able to narrow it down to either calling destroy on our character that uses mecanim, or it is in instantiating a second (or subsequent) instance of our character prefab that uses mecanim. It’s just impossible to know where the bug is occurring exactly because Unity crashes and we get no useful error being reported. We would have thought that Unity would have given us a proper null exception in the console, not crashing the player/editor. It’s incredibly frustrating and is stifling a major production, we need some help on this asap!!

2) How can we reproduce it using the example you attached.

(I’ve modified the description of how to produce the bug so it will make sense to someone without access to the project/application)

Basically, I’m instantiating a character from a prefab that uses mecanim into a game scene. If I destroy the character and then re-instantiate a new instance, even after delays to make sure the old one is fully gone, the Unity editor will crash. If I remove the character from being created, the rest of my scene can be cleaned up and recreated and doesn’t crash, add the character back in and it crashes once again.

This crash also affects the web player, however the bug becomes much more erratic, we are usually able to cycle through the steps and create and destroy the character up to 5-6 times before the crash occurs. Sometime it will happen after a couple of times, sometimes as much as 20 cycles before it will occur. Again, if we remove the character from being spawned, the web player will cycle through without a crash, I’ve made it through 60 times without a crash without the character.

I’ve also tried removing our script character controller component called TheBoyController.cs from the character prefab, so that none of our code is running after the character is instantiated, this seems to help the editor to stop from crashing, but doesn’t change the outcome for the web player which still crashes erratically. Then I tried to narrow down our code by removing bit by bit, but all this achieved was an erratic crashing behaviour in the editor, it still crashed but become erratic like the web player. My gut feeling is that the unhanded exception is coming from mechanim internal runtime classes.

I’m using the latest version of Unity 4.1.2 with a pro license, on a mac pro with 10.8.3. As I mentioned we need a solution to this asap!! In the meantime the only course of action I have is to only create this character once and to never destroy it… seems ridiculous though, I’m going to run into this problem again very soon when I go to instantiate multiple npc instances from a single prefab source.

PS: ironically the crash reporter is also generating it’s stack trace because it doesn’t have access to my address book, I’m not sure if this is an exception or not…

Receiving unhandled NULL exception
Launching bug reporter

*** Launching bug reporter due to crashbug.
Obtained 0 stack frames.
2013-04-15 12:30:14.189 Unity Bug Reporter[3365:1203] Address book access is denied for executable at path: /Applications/Unity/Unity Bug Reporter.app/Contents/MacOS/Unity Bug Reporter
(
0 AddressBook 0x90f852da __ABIsAccessGranted_block_invoke_0 + 39
1 libdispatch.dylib 0x96d0ac82 _dispatch_client_callout + 46
2 libdispatch.dylib 0x96d0abf1 dispatch_once_f + 57
3 libdispatch.dylib 0x96d0b831 dispatch_once + 31
4 AddressBook 0x90f85222 ABIsAccessGranted + 50
5 AddressBook 0x90f85116 +[ABAddressBook sharedAddressBook] + 35
6 Unity Bug Reporter 0x00004c89 -[BugReporter finishLaunching] + 341
7 AppKit 0x979323a9 -[NSApplication run] + 196
8 AppKit 0x978d5666 NSApplicationMain + 1053
9 Unity Bug Reporter 0x000031cc main + 482
10 Unity Bug Reporter 0x00002972 _start + 216
11 Unity Bug Reporter 0x00002899 start + 41
12 ??? 0x00000006 0x0 + 6
):

Jason Rawlings
Millipede Creative Development

Another twist to add … I thought I might try and isolate the bug even further by exporting a package of the character prefab into a fresh project, everything I found seems to point to mecanim as being the cause. So I created a project that will instantiate the character and then destroy it every second. The annoying thing is that test project works without any crashes occurring… arrrrrrr… so frustrating, I think I’m at a brick wall on being able to narrow down where the crash is coming from… help

That call stack describes another problem that may indeed be confusing the issue.

You need to manually allow the bug reporter access your contacts. In the System Preferences, open the Security Privacy section. Select the Privacy tab. Find Labels Addresses in the list and set its check box.

Once you’ve done that it should hopefully give you a correct call stack that will help isolating the problem.

Thanks for the suggestion I really appreciate it, because we need to get to the bottom of this asap… but unfortunately that didn’t change the outcome. I’ve granted it access to my contacts, and the stacktrace from the bug reporter has gone away, but the ambiguous unhandled NULL exception remains:

Receiving unhandled NULL exception
Launching bug reporter

*** Launching bug reporter due to crashbug.
Obtained 0 stack frames.

Hmm, I doubt I have to tell you that no call stack = bad. Can you try to reproduce it on windows? The code that obtains call stacks in mac and windows is completely separated so we might get lucky.

Update: The bug report was sent and responded to very quickly… thanks guys!! The support team beat me to it and gave it a run on Windows and it appears the crash is related to physX. It’s been passed onto the dev team.

BUG FIXED: so I submitted my project to the Unity dev team, it turns out the bug was a known bug but was not reproducible and was too hard to track and fix. However in my project it could be consistently reproduced, apparently the bug fix will be out with Unity 4.2.

Just wish I had a clue about when 4.2 will be out…

Just got Unity 4.2 and can confirm that the crash has been fixed!!! =) very happy

To clarify, this bug may have had nothing to do with mecanim in the end, my best guess is that it was this from the release notes that fixed it:

Physics: Fixed a crash related to destroying colliders while Time.timeScale is zero.

Thanks!!!