realm-dotnet icon indicating copy to clipboard operation
realm-dotnet copied to clipboard

Realm 20.1.0 no longer closes Realms when stopping Unity player

Open peachypixels opened this issue 10 months ago • 1 comments

What happened?

Hello!

I'm noticing different behaviour between 12.5.0 and 20.1.0 with regards to quitting the Unity player and open Realms (see repro steps)

I've no idea if this happens when running on production\device builds. It doesn't appear to be causing any issues in on-device beta testing, but maybe OS sandboxing is 'helping' here with regards to open files \ file handles.

I can see that the closing\cleanup call originates from Initializer.Initialize that then calls NativeCommon.CleanupNativeResources on the Unity Application.quitting callback.

There are some subtle differences between the two versions, but I'm not in a position to look any further into the issue. Sorry.

So just raising it here in-case someone is able to confirm it's not a bug or that they can investigate further.

Repro steps

Running in Unity then stopping the player, the following used to occur with (12.5.0)...

  1. Realm is open
  2. Unity player is stopped (but not closed)
  3. Logging [Realm.SDK Info: Realm: Force closing all native instances: Application is exiting]
  4. Logging [Realm.SDK Info: Realm: Closed all native instances in NN ms]
  5. Realm is closed (tested by attempting to rename file)

But with (20.1.0) the following occurs...

  1. Realm is open
  2. Unity player is stopped (but not closed)
  3. Realm is still open (tested by attempting to rename file)

Version

Unknown

What Atlas Services are you using?

Local Database only

What type of application is this?

Unity

Client OS and version

Windows 10 (22H2)

Code snippets

No response

Stacktrace of the exception/crash you're getting


Relevant log output


peachypixels avatar Feb 28 '25 16:02 peachypixels

Some extra info that I should have posted last week.

This issue was replicated (with Unity 2022.3.59f1) by switching between the two different Realm versions.

Assuming Initializer.Initialize is succeeding (highly likely) then I suspect the issue is actually with NativeCommon.CleanupNativeResources

Specifically, the following Realm initialised check...

https://github.com/realm/realm-dotnet/blob/353b2ba4e3f78a1a588ef784d82c53f7f9edd177/Realm/Realm/Native/NativeCommon.cs#L90

I suspect by the time Unity invokes the quitting callback, the Realm initialised flag is false (or 0) even though Realm hasn't closed\released what it needs to.

Anyway, hopefully this helps.

peachypixels avatar Mar 03 '25 10:03 peachypixels