Crash on IOS Bio Security Login with local Realm data

I have a frustrating crash occurring in my App.
I would welcome any help or advice.
I feel it must be something fundamental i have wrong as i cannot believe my use case is unique.
The App is built in SwiftUI and uses Realm Sync.
Xcode 12.4. latest releases of IOS

All was going good until I added a local realm in memory DB (i have also tried to file)
There is nothing special about the code.
It just renders a Scroll View of data items and allows the use to select individual items - toggle a status field.
I have the following crash occurring

Thread 1: EXC_BAD_ACCESS (code=1, address=0x3f)
AttributeID, unsigned Int - see attached

The crash only occurs when I logout of the App and re-login in via the biometrics option.
When the following default login screen appears.
It is a consistent crash.

I have narrowed down the unique situation the crash occurs.

The crash only occurs when i present and update the data from the local Realm DB in a SwiftUI View.
(ie toggle a data field) The update is rendered ok and all seems fine.

I have tried Modals and Nav links - all have the same result.

if i do not update the data from within the View - all is ok.

If i update the data via Realm Studio - the update is rendered ok within the App and it does not cause a crash.

If I attach the Realm data manipulation View to the main App Tab bar (whether i enter the Tabar View or not) - All is OK! … I can update the local Realm data via any App View and it does not cause and crash on re-login.

Any help or thoughts appreciated.

@Damian_Raffell It sounds like you might be blocking the main thread with your Realm write. Have you tried to move the writes to a serial queue?

Thanks for responding …

I don’t think i am blocking the main thread. The App all works fine and responds well.
The local Realm is loaded off the main thread on a serial queue. But the App does not even get that far.

Its only after i logout and try to log in again (which logs out of Sync, but i don’t think its anything to do with that, data updates all work fine and do not cause this crash) - its only after updating my local Realm data.

It happens right here in the code. While waiting for User response. It never executes the login closure.

I am seeing this also

2021-03-30 11:57:57.517931+0100 NaturalBritain[15199:642006] [error] precondition failure: accessing attribute in a different namespace: 2777808

CoreSimulator 732.18.6 - Device: iPhone 12 Pro (E8B7D200-AC93-4962-B9AA-45873FCF2993) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 12 Pro

AttributeGraph precondition failure: accessing attribute in a different namespace: 2777808.

Are you using the Realm SwiftUI property wrappers? Could you give us a full stack trace?

Hi OK … i think i have tracked this down.
No i wasn’t using the wrappers.
I was loading some of the data into an Oberservable Object with an @Published array for rendering within a Scroll View. Sometimes this array could be empty. Nothing complained until i logged out. I guess this array address got flushed further down the Nav stack, and the View couldn’t handle it.
I will put this issue on hold for now while i test further.

thanks for your support
I will have a look at the wrappers.

Final ending to this…
It wasn’t the array, it was the underlying List View (not a Scroll View) - i was loading into.
I guess it wasn’t preserving an accurate state somewhere.
The bio login was a misleading entry point.
I guess this is where SwiftUI tries to re-render the Views and it couldn’t do it.
I have changed to a LazyVS and all is good in the hood. - cheers

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.