-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Gdx.files being garbage collected in MultiplayerTurnCheckWorker #6817
Fix Gdx.files being garbage collected in MultiplayerTurnCheckWorker #6817
Conversation
1388de4
to
968118a
Compare
This is a little annoying to test, because it only occurs after like ~1 hour of running in the background. Apparently this was not enough. Probably got to save the |
Makes me curious at to what the symptoms actually look like - or what you see/don't see to determine "enough" |
I misunderstood how android |
0e4d65e
to
9b0bb1f
Compare
I have a fix in here now, but I want to refactor |
Actually there's no fucking reason to do that in this PR, please review :) |
If you're looking for excuses for skin shenanigans on github, sorry, wrong place. I ass-ume the conflicts are from #6847? |
# Conflicts: # android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt # core/src/com/unciv/logic/GameSaver.kt
I think conflicts came from #6822, but auto-resolve fixed all of them |
So the
Worker
in Android can be freely stopped & recreated by theWorkManager
. It is supposed to be a standalone "application" that can handle re-initialization.We do this slightly unconventional thing of making a new
OneTimeWorkRequestBuilder
recursively (every time it runs, a new work request is made for the next execution) instead of usingPeriodicWorkRequestBuilder
. I assume that because of that, our firstWorker
instance we started has been kept alive for longer than it was supposed to, and thus no new instance was ever created with usual player behavior.But apparently after a long time (multiple hours of the turn worker running on my phone), our Worker instance is stopped temporarily and then re-initialized by the
WorkManager
. So all the initialization that happened byAndroidLauncher
(which is anAndroidApplication
) that initialized the GDX variables is gone. This includesGdx.files
. Then, when the newWorker
is created, a newGameSaver
instance is also created. But this instance has so far been statically accessingGdx.files
, which is now gone.So what the solution is here is to create & pass the correct
[gdx].Files
instance to theGameSaver
on creation, instead of letting it useGdx.files
statically.Exception
Old description
It seems like since the addition of `runBlocking` in `MultiplayerTurnCheckWorker`, the `AndroidApplication` that initially started the background worker gets garbage collected. Which is actually as it should be imo. But the `GameSaver` still needs to work, which is why we need to add a reference to `Gdx.files` to it so it doesn't get garbage collected.