forked from SilverStudioGames/WTS
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:
parent
5eba0300c7
commit
f71070f7f3
@ -6,7 +6,7 @@ init offset = -2
|
||||
|
||||
init python in gui:
|
||||
import store
|
||||
from store import settings, ScreenshotImage
|
||||
from store import settings
|
||||
|
||||
init(1080, 600)
|
||||
|
||||
@ -60,11 +60,11 @@ init python in gui:
|
||||
renpy.store.disable_game_menu()
|
||||
renpy.choice_for_skipping()
|
||||
renpy.pause(0.001) # Give renderer the chance to catch up with transitions
|
||||
bg = ScreenshotImage.capture()
|
||||
renpy.call_in_new_context("gui_init_context", bg, label, *args, **kwargs)
|
||||
renpy.store.screenshot.capture()
|
||||
renpy.call_in_new_context("gui_init_context", label, *args, **kwargs)
|
||||
|
||||
label gui_init_context(bg, label, *args , **kwargs):
|
||||
$ renpy.show("screenshot", what=bg, at_list=[Transform(size=(config.screen_width, config.screen_height))])
|
||||
label gui_init_context(label, *args , **kwargs):
|
||||
$ renpy.show("screenshot", what=screenshot.image, at_list=[Transform(size=(config.screen_width, config.screen_height))])
|
||||
$ renpy.call(label, *args, **kwargs)
|
||||
return
|
||||
|
||||
|
@ -1,25 +1,19 @@
|
||||
|
||||
init -10 python:
|
||||
class ScreenshotImage(im.ImageBase):
|
||||
def __init__(self, root, **properties):
|
||||
super(ScreenshotImage, self).__init__(root, **properties)
|
||||
self.root = root
|
||||
# self.cache = False
|
||||
# Sometimes causes segfault, maybe only if cache = True?
|
||||
class ScreenshotImage(NoRollback):
|
||||
_image = None
|
||||
|
||||
def load(self):
|
||||
sw, sh = config.screen_width, config.screen_height
|
||||
render = renpy.display.render.render_screen(self.root, sw, sh)
|
||||
return renpy.display.draw.screenshot(render)
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def capture(retain=True):
|
||||
if retain:
|
||||
# Prevent the image from being recaptured after load
|
||||
renpy.retain_after_load()
|
||||
def capture(self):
|
||||
self._image = Transform(im.Data(renpy.screenshot_to_bytes(None), "screenshot.png"), size=(config.screen_width, config.screen_height))
|
||||
|
||||
root = renpy.display.core.scene_lists().make_layer("screens", {})
|
||||
return ScreenshotImage(root)
|
||||
@property
|
||||
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)):
|
||||
crop = crop or (0, 0, size[0], size[1])
|
||||
|
Loading…
Reference in New Issue
Block a user