I am trying to figure out why NSOutlineView is causing a crash when I delete a row and reloadData() gets called


#1

Just a copy of the issue I created. I created a test app to see if I can replicate the problem but I can’t. I have fixed the problem by simply creating a wrapper class to hold the Realm Object and the crash no longer occurs. If anyone has any suggestions on how to try and figure this one out please let me know. For now the wrapper class will have to do but it seems an unnecessary extra bit of work.

I used this https://github.com/realm/realm-cocoa/issues/1734 as the basis for trying to recreate the problem but was unable to. My apps code is basically identical but it seems like outlineView is trying to access the deleted objects property when reloadData() is called.

Goals

I am trying to use a NSOutlineView with Realm objects but can’t seem to find a workaround for deleting objects. It seems no matter what I try the OutlineView seems to try and access the realm object when removing it which causes a realm exception to be thrown.

Expected Results

I would expect to be able to delete the realm object and then trigger an update to NSOutlineView by calling reloadData() without an exception being thrown

Actual Results

See stack trace below - it’s not really clear to me why the reloadData() would crash give the object has been removed from the data source but it looks like outlineView is trying to access the object in some fashion

2019-06-07 19:46:40.548426+1000 MM[8485:1624551] [General] Object has been deleted or invalidated.
2019-06-07 19:46:40.554541+1000 MM[8485:1624551] [General] (
0 CoreFoundation 0x00007fff52c21cfd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff7d2c8a17 objc_exception_throw + 48
2 Realm 0x00000001012d499c ___ZN12_GLOBAL__N_115makeBoxedGetterIN5realm10StringDataEEEP11objc_objectm_block_invoke + 285
3 Foundation 0x00007fff54dd98c5 -[NSObject(NSKeyValueCoding) valueForKey:] + 281
4 Realm 0x00000001012ef898 -[RLMObjectBase valueForKey:] + 85
5 Realm 0x00000001012f0b44 -[RLMObjectBase hash] + 145
6 Foundation 0x00007fff54dc2176 probeGC + 79
7 Foundation 0x00007fff54e0d829 -[NSConcreteMapTable removeObjectForKey:] + 53
8 AppKit 0x00007fff504486e9 _NSOVFreeRowEntry + 59
9 AppKit 0x00007fff5044864f _NSOVRecursiveFreeChildrenAndItem + 121
10 AppKit 0x00007fff5043c9a6 _NSOVFastRemoveChildRowEntries + 216
11 AppKit 0x00007fff5043c882 -[NSOutlineView reloadData] + 564

Steps to Reproduce

I can’t seem to reproduce this in a test app. Actually I can reproduce this - here the test app, which I have subsequently modified to work around the issue by marking the objects with an isDeleted flag to prevent the exception being thrown. Uncomment the marked lines to reproduce the crash.

Code Sample

realm.beginWrite()
realm.delete(item)

        do {
            try realm.commitWrite()
            
            self.outlineView?.reloadData()
            
        } catch {
           
        }

Version of Realm and Tooling

Realm framework version: latest version

Realm Object Server version: Na

Xcode version: 10.21

iOS/OSX version: macOS 10.14.5

Dependency manager + version: Na