Crash in enumerateDisplaysWithBlock using Metal

Hi,

We’ve got an update in review with Apple which has been rejected because of an uncaught exception on launch in the UnityGfxDeviceWorker thread. This is the exception:

*** Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘*** Collection <NSConcreteMapTable: 0x13dd8b3c0> was mutated while being enumerated.’

The symbolicated callstack looks like this:

-[NSException name] (in CoreFoundation) + 0
-[NSConcreteMapTable countByEnumeratingWithState:objects:count:] (in Foundation) + 76
-[DisplayManager enumerateDisplaysWithBlock:] (in resynth) + 288
UnityStartFrameRendering (in resynth) + 52
GfxDeviceMetal::BeginFrame() (in resynth) (GfxDeviceMetal.mm:1606)
GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) (in resynth) (GfxDeviceWorker.cpp:1053)
GfxDeviceWorkerAutoreleasePoolProxy (in resynth) (GfxDeviceMetal.mm:1826)
GfxDeviceWorker::Run() (in resynth) (GfxDeviceWorker.cpp:328)
GfxDeviceWorker::RunGfxDeviceWorker(void*) (in resynth) (GfxDeviceWorker.cpp:316)
Thread::RunThreadWrapper(void*) (in resynth) (Thread.cpp:44)

We’re using Unity 5.4.3f1. The device the tester was using was running iOS 10.3.1 and it was an iPhone 6s Plus (hardware model iPhone8,2).

I haven’t been able to find anything in the issue tracker about this. Is this a known crash? Has it been fixed in another Unity version? I haven’t seen it happen before anywhere else on other iOS versions (I myself am on 10.3.2 at the moment and don’t have a 10.3.1 device to test with).

Thanks,
Sam

We have the same issue after we submit a test ipa to Testflight. We can run app on our device successfully, but Testflight Reviewer feedback this error. Our Unity version is 5.5.2f1.

Last Exception Backtrace:
0   CoreFoundation                    0x18a2211b8 0x18a0f1000 + 1245624
1   libobjc.A.dylib                   0x188c5855c 0x188c50000 + 34140
2   CoreFoundation                    0x18a220c00 0x18a0f1000 + 1244160
3   Foundation                        0x18ac3ba08 0x18ac2b000 + 68104
4   wzlz                              0x10002cb24 -[DisplayManager enumerateDisplaysWithBlock:] (DisplayManager.mm:322)
5   wzlz                              0x10002d654 UnityStartFrameRendering (DisplayManager.mm:504)
6   wzlz                              0x100df1180 GfxDeviceMetal::BeginFrame() (GfxDeviceMetal.mm:1855)
7   wzlz                              0x100a8ce94 GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) (GfxDeviceWorker.cpp:442)
8   wzlz                              0x100df2660 GfxDeviceWorkerAutoreleasePoolProxy (GfxDeviceMetal.mm:2510)
9   wzlz                              0x100a8f1b0 GfxDeviceWorker::Run() (GfxDeviceWorker.cpp:344)
10  wzlz                              0x100a895e0 GfxDeviceWorker::RunGfxDeviceWorker(void*) (GfxDeviceWorker.cpp:308)
11  wzlz                              0x100caf7f8 Thread::RunThreadWrapper(void*) (Thread.cpp:35)
12  libsystem_pthread.dylib           0x1892b5850 0x1892b2000 + 14416
13  libsystem_pthread.dylib           0x1892b5760 0x1892b2000 + 14176
14  libsystem_pthread.dylib           0x1892b2d94 0x1892b2000 + 3476

Mclockw

Also experiencing this issue in 2017.3f1 and is crashing on iPad Air 2. I was wondering if you managed to find a solution.

I did not recieve this error before and I do not know what caused it. I saw some similar posts about metal and multithreaded rendering so I am going to try to submit it for review with multithreaded rendering turned off.

Last Exception Backtrace:

0 CoreFoundation 0x180efb164 __exceptionPreprocess + 124 (NSException.m:166)
1 libobjc.A.dylib 0x180144528 objc_exception_throw + 56 (objc-exception.mm:521)
2 CoreFoundation 0x180efa7f0 __NSFastEnumerationMutationHandler + 128 (NSEnumerator.m:133)
3 Foundation 0x1817f9d84 -[NSConcreteMapTable countByEnumeratingWithState:objects:count:] + 76 (NSMapTable.m:1018)
4 --- 0x00000001009a1698 0x000000010098c000 + 87703
5 --- 0x000000010099b3a8 -[UnityAppController(Rendering) callbackPresent:] + 62375 (UnityAppController+Rendering.mm:114)
6 --- 0x000000010099b94c UnityPresentContextCallback + 63819 (UnityAppController+Rendering.mm:152)
7 --- 0x000000010138f658 GfxDeviceMetal::PresentFrame() + 10499671 (GfxDeviceMetal.mm:2754)
8 --- 0x000000010180d330 GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) + 15209263 (GfxDeviceWorker.cpp:1165)
9 --- 0x0000000101390ce8 GfxDeviceWorkerAutoreleasePoolProxy + 10505447 (GfxDeviceMetal.mm:3473)
10 --- 0x000000010180decc GfxDeviceWorker::RunExt(ThreadedStreamBuffer&) + 15212235 (GfxDeviceWorker.cpp:143)
11 --- 0x00000001018061a0 GfxDeviceWorker::RunGfxDeviceWorker(void*) + 15180191 (GfxDeviceWorker.cpp:310)
12 --- 0x000000010156381c Thread::RunThreadWrapper(void*) + 12417051 (Thread.cpp:36)
13 libsystem_pthread.dylib 0x180b242b4 _pthread_body + 308 (pthread.c:740)
14 libsystem_pthread.dylib 0x180b24180 _pthread_start + 312 (pthread.c:799)
15 libsystem_pthread.dylib 0x180b22b74 thread_start + 4

I ended up updating to 5.4.3p4. I forget whether that was for something else or for this bug specifically. I haven’t seen the bug since then, though. But you’re on a different version entirely so it sounds like the bug is still there… :confused:

-Sam

Hey Sam, thanks for your response. It could be a slightly different bug so if I find a solution I’ll let you know.

Hey Sam,

The app passed the review. Disabling multithreaded rendering did the trick.
Hope it will help someone.

Simon

This is still happening in 2017.4.0f1, yikes. Got my release delayed because of this.