Is there a memory leak in 'renpy.Render.canvas()'?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
ToxicTractor
Newbie
Posts: 1
Joined: Wed Jan 10, 2024 6:01 pm
Github: ToxicTractor
Contact:

Is there a memory leak in 'renpy.Render.canvas()'?

#1 Post by ToxicTractor »

Hello!

Let me start by providing a little context. I was playing around with creator-defined displayables and was trying to create a simple, paint-like minigame. I noticed that RenPy seemed to slow down considerably after some time, and it turns out it was using more than 10 gigabytes of memory.

I searched around to figure out if others have had this issue, but I was unable to find anything.

I was able to narrow the issue down to this: Accessing the canvas of the render object by calling 'renpy.Render.canvas()' and then redrawing the screen using 'renpy.redraw(self, 0)' will cause memory usage to build up. The weird thing is that it doesn't actually seem to crash but stops just shy of using 100% of my system's memory.

I realise that this might be caused by me doing something wrong, but I have no idea what it is. The code below is a very simple demonstration of the problem. Does anyone know what is going on here?

Code: Select all

init python:
    
    class MyCDD(renpy.Displayable):
        def __init__(self):
            renpy.Displayable.__init__(self)


        def render(self, width, height, st, at):
            r = renpy.Render(width, height)
            
            canvas = r.canvas() ## this seems to be the cause

            canvas.circle("#f00", self.mousePos, 20) ## the issue persists even if I remove this line

            renpy.redraw(self, 0)

            return r


screen testscreen:
    modal True

    add MyCDD()


label start:
    show screen testscreen

    pause

Post Reply

Who is online

Users browsing this forum: Ocelot