2022-07-07 21:05:22 +00:00
|
|
|
init python:
|
2022-06-27 21:31:51 +00:00
|
|
|
|
|
|
|
if renpy.android:
|
2022-07-07 21:05:22 +00:00
|
|
|
settings.default("crashdefendersetting", 0)
|
|
|
|
|
2022-06-27 21:31:51 +00:00
|
|
|
# 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
|
2022-07-07 21:05:22 +00:00
|
|
|
|
|
|
|
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
|
2022-06-27 21:31:51 +00:00
|
|
|
|
|
|
|
def __call__(self, name):
|
2022-07-07 21:05:22 +00:00
|
|
|
if renpy.is_init_phase() or self.limit == 0:
|
2022-06-27 21:31:51 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
self.statements += 1
|
|
|
|
|
|
|
|
if self.statements > self.limit:
|
|
|
|
self.statements = 0
|
|
|
|
|
|
|
|
# Big thanks to Andykl (https://github.com/Andykl)
|
|
|
|
# for finding the issue and inventing this workaround.
|
|
|
|
# https://github.com/renpy/renpy/issues/3643
|
|
|
|
|
|
|
|
cache = renpy.display.im.cache
|
|
|
|
cache_size = cache.get_total_size()
|
|
|
|
cache_limit = cache.cache_limit * 0.95
|
|
|
|
|
|
|
|
if cache_size >= cache_limit:
|
|
|
|
if config.developer:
|
|
|
|
print("Cache limit reached, purging cache... ({}/{})\n{}".format(cache_size, cache_limit, renpy.get_filename_line()))
|
|
|
|
|
|
|
|
cache.clear()
|
|
|
|
|
|
|
|
if renpy.game.interface is not None:
|
|
|
|
if config.developer:
|
|
|
|
print("Statements limit reached, cleaning textures... ({})\n{}".format(self.limit, renpy.get_filename_line()))
|
|
|
|
|
|
|
|
renpy.game.interface.full_redraw = True
|
|
|
|
renpy.game.interface.restart_interaction = True
|
|
|
|
|
|
|
|
if renpy.display.draw is not None:
|
|
|
|
renpy.display.draw.kill_textures()
|
|
|
|
|
|
|
|
renpy.display.render.free_memory()
|
|
|
|
|
2022-07-07 21:05:22 +00:00
|
|
|
crashdefender = Android11TextureLeakFix()
|
|
|
|
|
|
|
|
config.statement_callbacks.append(crashdefender)
|
|
|
|
|
2023-01-03 21:27:35 +00:00
|
|
|
init python early:
|
2022-06-27 21:31:51 +00:00
|
|
|
|
|
|
|
if renpy.windows:
|
|
|
|
# On windows, Renpy does not support backslashes in some of its functions,
|
|
|
|
# but because the code needs to be platform-independent,
|
|
|
|
# we require to monkey patch those functions in order
|
|
|
|
# to remain compatible with all platforms without losing functionality.
|
|
|
|
|
|
|
|
@renpy.pure
|
|
|
|
def _loadable(filename):
|
|
|
|
filename = filename.replace("\\", "/")
|
|
|
|
|
2022-06-29 18:46:19 +00:00
|
|
|
return renpy.loader.loadable(filename)
|
2022-06-27 21:31:51 +00:00
|
|
|
|
|
|
|
renpy.loadable = _loadable
|
2023-01-03 21:27:35 +00:00
|
|
|
|
|
|
|
# renpy.list_files does not use cached results, let's fix that.
|
|
|
|
|
|
|
|
def _list_files(common=False, quick=True):
|
|
|
|
cache = "_list_files_common_cache" if common else "_list_files_cache"
|
|
|
|
files = getattr(renpy.store, cache, [])
|
|
|
|
|
|
|
|
if not quick or not files:
|
|
|
|
rv = [fn for dir, fn in renpy.loader.listdirfiles(common) if not fn.startswith("saves/")]
|
|
|
|
rv.sort()
|
|
|
|
|
|
|
|
setattr(renpy.store, cache, rv)
|
|
|
|
|
|
|
|
return files
|
|
|
|
|
|
|
|
renpy.list_files = _list_files
|