-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Leak related to unload and rendering #306
Comments
Hello, One thing I see in your scene which could create/store framebuffers would be the light, which can comnpute depth buffers to compute (optionnally) shadows. You can try to just disable the LightManager/DirectionalLight to see if this is the culprit. |
Just one thing for your sceme : if you are using the latest version, you dont need anymore the CImgPlugin to load bmp, as it is now handled natively in the core by the STB utility header (Sofa.Helper) |
Hi @fredroy Sadly it even leaks, when there are absolutely no components but the root node. import Sofa
from tqdm import tqdm
import Sofa.Core
import Sofa.Simulation
import Sofa.SofaGL
# import SofaRuntime
import os
import time
import numpy as np
sofa_directory = os.environ["SOFA_ROOT"]
import pygame
from OpenGL.GL import *
from OpenGL.GLU import *
display_size = (600, 600)
def init_display(node):
pygame.display.init()
pygame.display.set_mode(display_size, pygame.DOUBLEBUF | pygame.OPENGL)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_LIGHTING)
glEnable(GL_DEPTH_TEST)
Sofa.SofaGL.glewInit()
Sofa.Simulation.initVisual(node)
Sofa.Simulation.initTextures(node)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, (display_size[0] / display_size[1]), 0.1, 50.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def simple_render(rootNode):
"""
Get the OpenGL Context to render an image (snapshot) of the simulation state
"""
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_LIGHTING)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, (display_size[0] / display_size[1]), 0.1, 50.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
# cameraMVM = rootNode.InteractiveCamera.getOpenGLModelViewMatrix()
cameraMVM = np.identity(4)
glMultMatrixd(cameraMVM)
Sofa.SofaGL.draw(rootNode)
pygame.display.get_surface().fill((0, 0, 0))
pygame.display.flip()
def createScene(root):
pass
# root.addObject("InteractiveCamera", widthViewport=display_size[0], heightViewport=display_size[1])
if __name__ == "__main__":
root = Sofa.Core.Node("myroot")
createScene(root)
Sofa.Simulation.init(root)
with_window = True
if with_window:
init_display(root)
for i in tqdm(range(300)):
Sofa.Simulation.animate(root, root.getDt())
Sofa.Simulation.updateVisual(root)
if with_window:
simple_render(root)
if i % 10 == 0:
if with_window:
pygame.display.quit()
Sofa.Simulation.unload(root)
createScene(root)
Sofa.Simulation.init(root)
if with_window:
init_display(root)
else:
time.sleep(0.001) |
Hi,
there is another memory leak, this time related to rendering in combination with
simulation.unload
.As a testing scene, I took the pygame example from SofaPython3 and added a reload to every tenth step.
The leak seems to be related to the OpenGL context, because for
31
init_display
calls, I get and AddressSanitizer output ofthat matches the lost amount of memory.
And it also veeeery closely matches the amount of memory required to store 31 RGBA buffers of the set image size. :D
If no display is created, there is no leak.
@fredroy Do you maybe know what could be the issue here?
Cheers,
Paul
The text was updated successfully, but these errors were encountered: