Memory Leak fix

* Fixed a memory leak inside ScreenshotImage class due to unsafe access and storage of list of renders
This commit is contained in:
LoafyLemon 2023-03-24 15:36:21 +00:00
parent 5eba0300c7
commit f71070f7f3
2 changed files with 16 additions and 22 deletions

View File

@ -6,7 +6,7 @@ init offset = -2
init python in gui: init python in gui:
import store import store
from store import settings, ScreenshotImage from store import settings
init(1080, 600) init(1080, 600)
@ -60,11 +60,11 @@ init python in gui:
renpy.store.disable_game_menu() renpy.store.disable_game_menu()
renpy.choice_for_skipping() renpy.choice_for_skipping()
renpy.pause(0.001) # Give renderer the chance to catch up with transitions renpy.pause(0.001) # Give renderer the chance to catch up with transitions
bg = ScreenshotImage.capture() renpy.store.screenshot.capture()
renpy.call_in_new_context("gui_init_context", bg, label, *args, **kwargs) renpy.call_in_new_context("gui_init_context", label, *args, **kwargs)
label gui_init_context(bg, label, *args , **kwargs): label gui_init_context(label, *args , **kwargs):
$ renpy.show("screenshot", what=bg, at_list=[Transform(size=(config.screen_width, config.screen_height))]) $ renpy.show("screenshot", what=screenshot.image, at_list=[Transform(size=(config.screen_width, config.screen_height))])
$ renpy.call(label, *args, **kwargs) $ renpy.call(label, *args, **kwargs)
return return

View File

@ -1,25 +1,19 @@
init -10 python: init -10 python:
class ScreenshotImage(im.ImageBase): class ScreenshotImage(NoRollback):
def __init__(self, root, **properties): _image = None
super(ScreenshotImage, self).__init__(root, **properties)
self.root = root
# self.cache = False
# Sometimes causes segfault, maybe only if cache = True?
def load(self): def __init__(self):
sw, sh = config.screen_width, config.screen_height pass
render = renpy.display.render.render_screen(self.root, sw, sh)
return renpy.display.draw.screenshot(render)
@staticmethod def capture(self):
def capture(retain=True): self._image = Transform(im.Data(renpy.screenshot_to_bytes(None), "screenshot.png"), size=(config.screen_width, config.screen_height))
if retain:
# Prevent the image from being recaptured after load
renpy.retain_after_load()
root = renpy.display.core.scene_lists().make_layer("screens", {}) @property
return ScreenshotImage(root) def image(self):
return self._image
screenshot = ScreenshotImage()
def displayable_to_file(d, path, size=(config.screen_width, config.screen_height), crop=None, coloralpha=(0, 255, 0)): def displayable_to_file(d, path, size=(config.screen_width, config.screen_height), crop=None, coloralpha=(0, 255, 0)):
crop = crop or (0, 0, size[0], size[1]) crop = crop or (0, 0, size[0], size[1])