crisp-sdk-ios
crisp-sdk-ios copied to clipboard
[CRASH] - ChatContentViewController.swift - Line 692
I'm experiencing a crash caused by the ChatContentViewController.updateAlertView() function.
The description of the crash is
Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Stacktrace
0 CoreFoundation 0x18fcbb754 __exceptionPreprocess
1 libobjc.A.dylib 0x1a47827a8 objc_exception_throw
2 CoreAutoLayout 0x1a4a0d7d0 -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints]
3 CoreAutoLayout 0x1a4a0dab0 -[NSISEngine withBehaviors:performModifications:]
4 UIKitCore 0x192bd5678 -[UIView(Hierarchy) _postMovedFromSuperview:]
5 UIKitCore 0x192be44bc -[UIView(Internal) _addSubview:positioned:relativeTo:]
6 Crisp 0x105233a04 ChatContentViewController.updateAlertView() + 692 (ChatContentViewController.swift:692)
7 Crisp 0x105233458 ChatContentViewController.chatViewModelDidUpdateState(_:oldState:) + 456 (ChatContentViewController.swift:456)
8 Crisp 0x10528f3d8 ChatViewModel.state.setter + 66 (ChatViewModel.swift:66)
9 Crisp 0x10528fca4 ChatViewModel.applyChangesFromStore() + 564 (ChatViewModel.swift:564)
10 Crisp 0x10530d890 WeakRef<>.storeStateDidChange(_:oldState:) + 227 (Store.swift:227)
11 Crisp 0x10530c18c Store.state.didset + 57 (Store.swift:57)
12 Crisp 0x10530ca50 Store.reduce(_:) + 149 (Store.swift:149)
13 Crisp 0x10530c760 closure #1 in Store.init(websiteID:sessionData:transport:) + 84 (Store.swift:84)
14 Crisp 0x105216450 closure #5 in closure #1 in variable initialization expression of LifecycleMiddleware + 40 (LifecycleMiddleware.swift:40)
15 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
16 Crisp 0x105350708 closure #1 in closure #1 in closure #1 in variable initialization expression of RequestUploadURLTimeoutMiddleware + 38 (RequestUploadURLTimeoutMiddleware.swift:38)
17 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
18 Crisp 0x1052f42e0 closure #1 in closure #1 in closure #1 in variable initialization expression of MarkDeliveryFailuresMiddleware + 38 (MarkDeliveryFailuresMiddleware.swift:38)
19 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
20 Crisp 0x105324e20 closure #1 in closure #1 in closure #1 in variable initialization expression of HeartbeatMiddleware + 38 (HeartbeatMiddleware.swift:38)
21 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
22 Crisp 0x1053255a4 closure #1 in closure #1 in closure #1 in variable initialization expression of DelayedGameInviteMessageMiddleware + 44 (DelayedGameInviteMessageMiddleware.swift:44)
23 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
24 Crisp 0x105277dc4 closure #1 in closure #1 in variable initialization expression of MessageAcknowledgementMiddleware + 17 (MessageAcknowledgementMiddleware.swift:17)
25 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
26 Crisp 0x10530a7e0 closure #1 in closure #1 in variable initialization expression of PersistSessionDataMiddleware + 23 (PersistSessionDataMiddleware.swift:23)
27 Crisp 0x10526a6a4 partial apply for closure #1 in closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
28 Crisp 0x10521a46c closure #1 in closure #1 in variable initialization expression of ServerStorageMiddleware + 106 (ServerStorageMiddleware.swift:106)
29 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
30 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
31 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
32 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
33 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
34 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
35 Crisp 0x10526a674 partial apply for closure #1 in closure #1 in static Middleware.<> infix(_:_:) (<compiler-generated>)
36 Crisp 0x10530e4c0 partial apply for closure #6 in Store.init(websiteID:sessionData:transport:) (<compiler-generated>)
37 Crisp 0x1052c0374 User.email.setter
38 tiimo 0x1048e8974 specialized CrispDriver.addUserinfo(withEmail:userID:) + 27 (CrispDriver.swift:27)
39 tiimo 0x1047f8cb4 closure #1 in TabBarViewController.verifyUserAuthentication() (<compiler-generated>)
40 tiimo 0x1048eaf28 closure #1 in closure #1 in Auth0Driver.verifyAuthentication(_:) + 130 (Auth0Driver.swift:130)
41 tiimo 0x1048ebc58 partial apply for closure #1 in closure #1 in Auth0Driver.verifyAuthentication(_:)
42 tiimo 0x1048ebbd8 partial apply for thunk for @escaping @callee_guaranteed (@guaranteed Result<Credentials, Error>) -> () (<compiler-generated>)
43 Auth0 0x104f52004 specialized authenticationObject<A>(from:callback:) + 57 (Handlers.swift:57)
44 Auth0 0x104f89000 closure #1 in Request.start(_:) + 93 (Request.swift:93)
45 Auth0 0x104f890a4 partial apply for closure #1 in Request.start(_:) (<compiler-generated>)
46 Auth0 0x104f89134 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () (<compiler-generated>)
47 CFNetwork 0x1902df3dc CFNetServiceBrowserSearchForServices
48 CFNetwork 0x1902f1768 _CFHTTPMessageSetResponseProxyURL
49 libdispatch.dylib 0x18f8a6a84 _dispatch_call_block_and_release
50 libdispatch.dylib 0x18f8a881c _dispatch_client_callout
51 libdispatch.dylib 0x18f8b0004 _dispatch_lane_serial_drain
52 libdispatch.dylib 0x18f8b0c34 _dispatch_lane_invoke
53 libdispatch.dylib 0x18f8bb4bc _dispatch_workloop_worker_thread
54 libsystem_pthread.dylib 0x1daca27a4 _pthread_wqthread
55 libsystem_pthread.dylib 0x1daca974c start_wqthread```
@baptistejamin this one happens especially on the iPad. Can you please take a look at it?
Hi @JMCPH. It looks like you're accessing the CrispSDK from a background thread. The SDK is not supposed to be thread-safe. Can you please make sure that you're calling into the SDK from the main thread? Thanks!
Hi @nesium,
Thanks for your reply.
To my knowledge we aren't calling anything in the ChatContentViewController or the SDK when the crash occurs.
The only thing we are setting is the email, userID and segment.
CrispSDK.user.email = email
CrispSDK.session.setString(userID ?? "", forKey: "userId")
CrispSDK.session.segment = "iOS"
Would that require to be called on the main-thread?
To me it seems to be an issue somewhere in the ChatContentViewController, when the chatViewModelDidUpdateState is called. We are presenting the ChatViewController from a main-thread, but the ChatContentViewController is private in the library.
At the moment it is only safe to interact with the SDK from the main thread. I understand your confusion, because it doesn't look like you're interacting with something UI related. This is definitively something we will improve upon in a future release.
@nesium I have just double checked and the setup code is performed on the main-thread 🤔
Hi everyone,
It’s been a while since this issue was reported, and we’ve launched a new major version of the Crisp SDK since then. The updates might have resolved the issue you encountered.
We’d appreciate it if you test the latest version to see if the issue persists. Feel free to reopen this issue with more details if needed.
Thanks for your support!