diff options
author | Germano <germano.costa@ig.com.br> | 2017-12-01 08:30:18 +0300 |
---|---|---|
committer | Germano <germano.costa@ig.com.br> | 2017-12-01 08:30:18 +0300 |
commit | 85bf5442d97c4576225777a8d2fc6c4a51b967e7 (patch) | |
tree | 45bd01c06c807df7ebd3fff0064b4c9431e8d11f /modules | |
parent | 0ec059ad19b88b1aaa2987b0e7355ad2dc91328b (diff) |
snap_context: Make sure that the elements of the class GPU_Indices_Mesh are freed at exit
This may solve some user application errors.
But the message "Error: Not freed memory blocks" still appears if blender is closed with the modal operator running :\
Diffstat (limited to 'modules')
-rw-r--r-- | modules/snap_context/__init__.py | 5 | ||||
-rw-r--r-- | modules/snap_context/mesh_drawing.py | 29 |
2 files changed, 28 insertions, 6 deletions
diff --git a/modules/snap_context/__init__.py b/modules/snap_context/__init__.py index 0c17b2cb..77e84726 100644 --- a/modules/snap_context/__init__.py +++ b/modules/snap_context/__init__.py @@ -191,6 +191,11 @@ class SnapContext(): def __del__(self): if not self.freed: self._offscreen.free() + # Some objects may still be being referenced + for snap_obj in self.snap_objects: + del snap_obj.data + del snap_obj.mat + del snap_obj del self.snap_objects ## PUBLIC ## diff --git a/modules/snap_context/mesh_drawing.py b/modules/snap_context/mesh_drawing.py index c85da506..bdfca4d3 100644 --- a/modules/snap_context/mesh_drawing.py +++ b/modules/snap_context/mesh_drawing.py @@ -159,11 +159,31 @@ class GPU_Indices_Mesh(): shader = None @classmethod + def end_opengl(cls): + del cls.shader + del cls._NULL + del cls.P + del cls.MV + del cls.MVP + del cls.vert_index + del cls.tri_co + del cls.edge_co + del cls.vert_co + + del cls + + @classmethod def init_opengl(cls): # OpenGL was already initialized, nothing to do here. if cls.shader is not None: return + import atexit + + # Make sure we only registered the callback once. + atexit.unregister(cls.end_opengl) + atexit.register(cls.end_opengl) + cls.shader = Shader( load_shader('3D_vert.glsl'), None, @@ -173,6 +193,8 @@ class GPU_Indices_Mesh(): cls.unif_use_clip_planes = bgl.glGetUniformLocation(cls.shader.program, 'use_clip_planes') cls.unif_clip_plane = bgl.glGetUniformLocation(cls.shader.program, 'clip_plane') + cls._NULL = gl_buffer_void_as_long(0) + cls.unif_MVP = bgl.glGetUniformLocation(cls.shader.program, 'MVP') cls.unif_MV = bgl.glGetUniformLocation(cls.shader.program, 'MV') cls.unif_offset = bgl.glGetUniformLocation(cls.shader.program, 'offset') @@ -182,6 +204,7 @@ class GPU_Indices_Mesh(): cls.P = bgl.Buffer(bgl.GL_FLOAT, (4, 4)) cls.MV = bgl.Buffer(bgl.GL_FLOAT, (4, 4)) + cls.MVP = bgl.Buffer(bgl.GL_FLOAT, (4, 4)) # returns of public API # cls.vert_index = bgl.Buffer(bgl.GL_INT, 1) @@ -193,10 +216,6 @@ class GPU_Indices_Mesh(): def __init__(self, obj, draw_tris, draw_edges, draw_verts): GPU_Indices_Mesh.init_opengl() - self._NULL = gl_buffer_void_as_long(0) - - self.MVP = bgl.Buffer(bgl.GL_FLOAT, (4, 4)) - self.obj = obj self.draw_tris = draw_tris self.draw_edges = draw_edges @@ -427,8 +446,6 @@ class GPU_Indices_Mesh(): def __del__(self): - del self._NULL - if self.vbo_tris: bgl.glDeleteBuffers(1, self.vbo_tris) bgl.glDeleteBuffers(1, self.vbo_tri_indices) |