HamzaGhazouani/HGPlaceholders

Crash in CollectionView.swift on line 153

sasojadrovski opened this issue · 3 comments

Hi @HamzaGhazouani,

I have noticed a strange crash that sometimes happens when switching between data sources. I cannot provide the exact steps on how to reproduce the issue, but I am sending you a stacktrace that might be of help. I also know (by setting an Exception breakpoint) that the crash occurs in the CollectionView.swift file on line 153.

Please take a look and let me know your findings.

# Platform: ios
# OS Version: 11.2.6 (15D100)
# Device: iPhone X

#0. Crashed: com.apple.main-thread
0  UIKit                          0x18d013660 -[UICollectionViewData layoutAttributesForItemAtIndexPath:] + 248
1  UIKit                          0x18da40fc4 -[UICollectionView _setCollectionViewLayout:animated:isInteractive:completion:animator:] + 2216
2  UIKit                          0x18d11a9a4 -[UICollectionView _setCollectionViewLayout:animated:isInteractive:completion:] + 84
3  UIKit                          0x18d11a930 -[UICollectionView setCollectionViewLayout:] + 392
4  HGPlaceholders                 0x1014f49e0 specialized CollectionView.collectionViewLayout.setter (CollectionView.swift)
5  HGPlaceholders                 0x1014f388c @objc CollectionView.collectionViewLayout.setter (CollectionView.swift)
6  HGPlaceholders                 0x1014f48d4 specialized CollectionView.switchTo(dataSource : UICollectionViewDataSource?, delegate : UICollectionViewDelegate?) -> () (CollectionView.swift:159)
7  HGPlaceholders                 0x1014f45e0 CollectionView.reloadData() -> () (CollectionView.swift:86)
8  HGPlaceholders                 0x1014f4624 @objc CollectionView.reloadData() -> () (CollectionView.swift)
9  AppName                      0x100f7c310 SearchCalendarsViewController.(bindViewModel() -> ()).(closure #1).(closure #1) (SearchCalendarsViewController.swift:46)
10 AppName                      0x100eab9dc specialized SearchCalendarsViewModel.(searchCalendars(term : String?, restartSearch : Bool, completion : ([IndexPath]?) -> ()) -> ()).(closure #1) (SearchCalendarsViewModel.swift:102)
11 AppName                      0x100eab2bc partial apply for SearchCalendarsViewModel.(searchCalendars(term : String?, restartSearch : Bool, completion : ([IndexPath]?) -> ()) -> ()).(closure #1) (SearchCalendarsViewModel.swift)
12 AppName                      0x100e76384 thunk (ChooseCalendarViewModel.swift)
13 AppName                      0x100eab34c partial apply for thunk (SearchCalendarsViewModel.swift)
14 PromiseKit                     0x1017942d0 specialized Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift:153)
15 PromiseKit                     0x10178d730 Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift)
16 PromiseKit                     0x101797074 partial apply for Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift)
17 PromiseKit                     0x1017a32e8 specialized State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift:51)
18 PromiseKit                     0x101798454 State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift)
19 PromiseKit                     0x1017a6b38 partial apply for State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift)
20 PromiseKit                     0x1017b335c specialized (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) (Zalgo.swift:78)
21 PromiseKit                     0x1017b32e0 (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) (Zalgo.swift)
22 PromiseKit                     0x1017738e4 thunk (after.swift)
23 libdispatch.dylib              0x183376a54 _dispatch_call_block_and_release + 24
24 libdispatch.dylib              0x183376a14 _dispatch_client_callout + 16
25 libdispatch.dylib              0x1833b7c80 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 968
26 CoreFoundation                 0x18399f344 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
27 CoreFoundation                 0x18399cf20 __CFRunLoopRun + 2012
28 CoreFoundation                 0x1838bcc58 CFRunLoopRunSpecific + 436
29 GraphicsServices               0x185768f84 GSEventRunModal + 100
30 UIKit                          0x18d0155c4 UIApplicationMain + 236
31 AppName                      0x100e49830 main (UICollectionViewCell+Utils.swift:12)
32 libdyld.dylib                  0x1833dc56c start + 4

--

#0. Crashed: com.apple.main-thread
0  UIKit                          0x18d013660 -[UICollectionViewData layoutAttributesForItemAtIndexPath:] + 248
1  UIKit                          0x18da40fc4 -[UICollectionView _setCollectionViewLayout:animated:isInteractive:completion:animator:] + 2216
2  UIKit                          0x18d11a9a4 -[UICollectionView _setCollectionViewLayout:animated:isInteractive:completion:] + 84
3  UIKit                          0x18d11a930 -[UICollectionView setCollectionViewLayout:] + 392
4  HGPlaceholders                 0x1014f49e0 specialized CollectionView.collectionViewLayout.setter (CollectionView.swift)
5  HGPlaceholders                 0x1014f388c @objc CollectionView.collectionViewLayout.setter (CollectionView.swift)
6  HGPlaceholders                 0x1014f48d4 specialized CollectionView.switchTo(dataSource : UICollectionViewDataSource?, delegate : UICollectionViewDelegate?) -> () (CollectionView.swift:159)
7  HGPlaceholders                 0x1014f45e0 CollectionView.reloadData() -> () (CollectionView.swift:86)
8  HGPlaceholders                 0x1014f4624 @objc CollectionView.reloadData() -> () (CollectionView.swift)
9  AppName                      0x100f7c310 SearchCalendarsViewController.(bindViewModel() -> ()).(closure #1).(closure #1) (SearchCalendarsViewController.swift:46)
10 AppName                      0x100eab9dc specialized SearchCalendarsViewModel.(searchCalendars(term : String?, restartSearch : Bool, completion : ([IndexPath]?) -> ()) -> ()).(closure #1) (SearchCalendarsViewModel.swift:102)
11 AppName                      0x100eab2bc partial apply for SearchCalendarsViewModel.(searchCalendars(term : String?, restartSearch : Bool, completion : ([IndexPath]?) -> ()) -> ()).(closure #1) (SearchCalendarsViewModel.swift)
12 AppName                      0x100e76384 thunk (ChooseCalendarViewModel.swift)
13 AppName                      0x100eab34c partial apply for thunk (SearchCalendarsViewModel.swift)
14 PromiseKit                     0x1017942d0 specialized Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift:153)
15 PromiseKit                     0x10178d730 Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift)
16 PromiseKit                     0x101797074 partial apply for Promise.(then<A> (on : DispatchQueue, execute : (A) throws -> A1) -> Promise<A1>).(closure #1).(closure #1) (Promise.swift)
17 PromiseKit                     0x1017a32e8 specialized State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift:51)
18 PromiseKit                     0x101798454 State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift)
19 PromiseKit                     0x1017a6b38 partial apply for State.(then<A> (on : DispatchQueue, else : (Resolution<A1>) -> (), execute : (A) throws -> ()) -> ()).(closure #1).(closure #1) (State.swift)
20 PromiseKit                     0x1017b335c specialized (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) (Zalgo.swift:78)
21 PromiseKit                     0x1017b32e0 (contain_zalgo<A> (DispatchQueue, rejecter : (Resolution<A>) -> (), block : () throws -> ()) -> ()).(closure #1) (Zalgo.swift)
22 PromiseKit                     0x1017738e4 thunk (after.swift)
23 libdispatch.dylib              0x183376a54 _dispatch_call_block_and_release + 24
24 libdispatch.dylib              0x183376a14 _dispatch_client_callout + 16
25 libdispatch.dylib              0x1833b7c80 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 968
26 CoreFoundation                 0x18399f344 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
27 CoreFoundation                 0x18399cf20 __CFRunLoopRun + 2012
28 CoreFoundation                 0x1838bcc58 CFRunLoopRunSpecific + 436
29 GraphicsServices               0x185768f84 GSEventRunModal + 100
30 UIKit                          0x18d0155c4 UIApplicationMain + 236
31 AppName                      0x100e49830 main (UICollectionViewCell+Utils.swift:12)
32 libdyld.dylib                  0x1833dc56c start + 4

#1. com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1834eb568 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1834eb3e0 mach_msg + 72
2  CoreFoundation                 0x18399f108 __CFRunLoopServiceMachPort + 196
3  CoreFoundation                 0x18399ccd4 __CFRunLoopRun + 1424
4  CoreFoundation                 0x1838bcc58 CFRunLoopRunSpecific + 436
5  Foundation                     0x1842f1594 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6  Foundation                     0x1843109ac -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7  UIKit                          0x18db7f7a8 -[UIEventFetcher threadMain] + 136
8  Foundation                     0x1843f30f4 __NSThread__start__ + 996
9  libsystem_pthread.dylib        0x1836202b4 _pthread_body + 308
10 libsystem_pthread.dylib        0x183620180 _pthread_body + 310
11 libsystem_pthread.dylib        0x18361eb74 thread_start + 4

#2. com.twitter.crashlytics.ios.MachExceptionServer
0  AppName                      0x100fa638c CLSProcessRecordAllThreads (CLSProcess.c:376)
1  AppName                      0x100fa638c CLSProcessRecordAllThreads (CLSProcess.c:376)
2  AppName                      0x100fa623c CLSProcessRecordAllThreads (CLSProcess.c:407)
3  AppName                      0x100f95870 CLSHandler (CLSHandler.m:26)
4  AppName                      0x100f9088c CLSMachExceptionServer (CLSMachException.c:446)
5  libsystem_pthread.dylib        0x1836202b4 _pthread_body + 308
6  libsystem_pthread.dylib        0x183620180 _pthread_body + 310
7  libsystem_pthread.dylib        0x18361eb74 thread_start + 4

#3. com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1834eb568 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1834eb3e0 mach_msg + 72
2  CoreFoundation                 0x18399f108 __CFRunLoopServiceMachPort + 196
3  CoreFoundation                 0x18399ccd4 __CFRunLoopRun + 1424
4  CoreFoundation                 0x1838bcc58 CFRunLoopRunSpecific + 436
5  CFNetwork                      0x1841abb08 -[__CoreSchedulingSetRunnable runForever] + 780
6  Foundation                     0x1843f30f4 __NSThread__start__ + 996
7  libsystem_pthread.dylib        0x1836202b4 _pthread_body + 308
8  libsystem_pthread.dylib        0x183620180 _pthread_body + 310
9  libsystem_pthread.dylib        0x18361eb74 thread_start + 4

#4. AVAudioSession Notify Thread
0  libsystem_kernel.dylib         0x1834eb568 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1834eb3e0 mach_msg + 72
2  CoreFoundation                 0x18399f108 __CFRunLoopServiceMachPort + 196
3  CoreFoundation                 0x18399ccd4 __CFRunLoopRun + 1424
4  CoreFoundation                 0x1838bcc58 CFRunLoopRunSpecific + 436
5  AVFAudio                       0x189225cd4 GenericRunLoopThread::Entry(void*) + 164
6  AVFAudio                       0x189250740 CAPThread::Entry(CAPThread*) + 84
7  libsystem_pthread.dylib        0x1836202b4 _pthread_body + 308
8  libsystem_pthread.dylib        0x183620180 _pthread_body + 310
9  libsystem_pthread.dylib        0x18361eb74 thread_start + 4

#5. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361f080 _pthread_wqthread + 1288
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

#6. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361eeec _pthread_wqthread + 884
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

#7. Thread
0  libsystem_pthread.dylib        0x18361eb68 start_wqthread + 122

#8. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361f080 _pthread_wqthread + 1288
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

#9. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361eeec _pthread_wqthread + 884
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

#10. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361f080 _pthread_wqthread + 1288
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

#11. Thread
0  libsystem_kernel.dylib         0x18350cd80 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x18361eeec _pthread_wqthread + 884
2  libsystem_pthread.dylib        0x18361eb6c start_wqthread + 4

Looking forward to hearing from you and once again, thanks for this awesome library!

Cheers,
Sasho

I have also noticed the same crash, hope this will be addressed at earliest.

Thanks
Sam

Hi guys,

For me, removing the line collectionViewLayout = placeholderLayout or changing it to collectionViewLayout = defaultLayout fixed the issue, without affecting the collection view layout in any way.

@HamzaGhazouani, please investigate this when you can :)

Thanks!

Hi Guys,
Thanks for your feed back, I will look at it as soon as possible
If you have any suggestion or a fix, please, don't hesitate to send a PR