IPhone UI addSubview throws concurrency exception

This is really weird ...

I run my application, and while it opens, and the views are created, I get:

Collection <CALayerArray: 0x124650> was mutated while being enumerated.

The code trace goes through the following:

main
UIApplicationMain
-[UIApplication _run]
CFRunLoopRunInMode
CFRunLoopRunSpecific
_UIApplicationHandleEvent
-[UIApplication sendEvent:]
-[UIApplication handleEvent:withNewEvent:]
-[UIApplication _runWithURL:sourceBundleID:]
-[UIApplication _performInitilizationWithURL:sourceBundleID:]
-[AppDelegate applicationDidFinishLaunching:]
+[Controller initializeController] //This is my own function
    [window addSubview: pauseMenuController.view] //This is the last point of my code it goes through
-[UIView(Hierarchy) addSubview:]
-[UIView(Internal) _addSubview:positioned:relativeTo:]
-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:]
-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]
-[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:]
_NSFastEnumerationMutationHandler
objc_exception_throw

I ran the game many times and many times, and I never saw this, and then suddenly appeared. The strange thing is that I do not create any other threads (which I know) until this code is called. It will be easier for me to debug this if someone can give me some explanation of what could be changed when it is available in UIView. Maybe this has something to do with adding something to the view, although it is already adding something? Any ideas?

+3
source share
5

concurrency. , - (, ) //, .

addSubview: , , - UIView .

, ? addSubview layoutSubviews? - subviews, .

+4

, , ? , (, ) _makeSubtreePerformSelector:withObject:withObject:copySublayers:, , , , .

, UIView , CALayer UIView, CALayer UIView, UIView . , CALayer UIView, UIView .

+16

:

"" - , , , .

, / (, ), , , Objective-C 2.0. .

. / , .

0

CALayers, CALayer -dealloc-, . , - -, -dealloc .

0
source

I got the same error. I was looking for a hierarchy of views on a non-core topic. Ensure that all changes to the view are made in the main thread.

0
source

Source: https://habr.com/ru/post/1722517/


All Articles