From 22588ba646902e289d71f0b4e97ad00e61da5415 Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Thu, 7 Jul 2022 22:05:22 +0100 Subject: [PATCH] Crash Defender * Fixed missing cache file from android builds * Added crash defender workaround for devices with borked OGL implementations --- game/scripts/gui/preferences.rpy | 11 +++++++++++ game/scripts/options.rpy | 3 +-- game/scripts/utility/engine.rpy | 25 +++++++++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/game/scripts/gui/preferences.rpy b/game/scripts/gui/preferences.rpy index 4684856f..7155b208 100644 --- a/game/scripts/gui/preferences.rpy +++ b/game/scripts/gui/preferences.rpy @@ -288,6 +288,17 @@ screen preferences_accessibility(): style gui.theme("pref_button") action Confirm(gui.CONFIRM_DELETE_SAVES, Function(delete_saves)) + if renpy.android: + label _("Android Crash Defender") + + hbox: + style_prefix gui.theme("radio") + + textbutton "Aggressive" action [settings.Set("crashdefendersetting", 3), Function(crashdefender.set_mode, 3)] + textbutton "Balanced" action [settings.Set("crashdefendersetting", 2), Function(crashdefender.set_mode, 2)] + textbutton "Relaxed" action [settings.Set("crashdefendersetting", 1), Function(crashdefender.set_mode, 1)] + textbutton "Off" action [settings.Set("crashdefendersetting", 0), Function(crashdefender.set_mode, 0)] + define gui.CONFIRM_DELETE_PERSISTENT = """{color=#7a0000}Warning!{/color} {size=-4}You are about to reset all persistent data, including achievements, seen text, and preferences.{/size}\n diff --git a/game/scripts/options.rpy b/game/scripts/options.rpy index 6ca8721b..93f33760 100644 --- a/game/scripts/options.rpy +++ b/game/scripts/options.rpy @@ -167,7 +167,6 @@ init python: build.classify("**.db", None) build.classify("**.zip", None) - build.classify("cache/**", None) + build.classify("cache/**", "android") build.classify("game/saves/**", None) build.classify("game/mods/**", None) - diff --git a/game/scripts/utility/engine.rpy b/game/scripts/utility/engine.rpy index 963ba6e8..9cd83601 100644 --- a/game/scripts/utility/engine.rpy +++ b/game/scripts/utility/engine.rpy @@ -1,15 +1,28 @@ -init -10 python: +init python: if renpy.android: + settings.default("crashdefendersetting", 0) + # Attempts at fixing the texture leak plaguing # android devices, mainly running on Android11 & Android 12. class Android11TextureLeakFix(NoRollback): def __init__(self, limit=100): self.statements = 0 - self.limit = limit + + self.set_mode(settings.get("crashdefendersetting")) + + def set_mode(self, mode): + if mode == 3: + self.limit = 15 + elif mode == 2: + self.limit = 25 + elif mode == 1: + self.limit = 55 + else: + self.limit = 0 def __call__(self, name): - if renpy.is_init_phase(): + if renpy.is_init_phase() or self.limit == 0: return self.statements += 1 @@ -43,7 +56,11 @@ init -10 python: renpy.display.render.free_memory() - config.statement_callbacks.append(Android11TextureLeakFix()) + crashdefender = Android11TextureLeakFix() + + config.statement_callbacks.append(crashdefender) + +init -10 python: if renpy.windows: # On windows, Renpy does not support backslashes in some of its functions,