[Bf-extensions-cvs] [85bf5442] master: snap_context: Make sure that the elements of the class GPU_Indices_Mesh are freed at exit
Germano
noreply at git.blender.org
Fri Dec 1 06:30:27 CET 2017
Commit: 85bf5442d97c4576225777a8d2fc6c4a51b967e7
Author: Germano
Date: Fri Dec 1 03:30:18 2017 -0200
Branches: master
https://developer.blender.org/rBA85bf5442d97c4576225777a8d2fc6c4a51b967e7
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 :\
===================================================================
M modules/snap_context/__init__.py
M modules/snap_context/mesh_drawing.py
===================================================================
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
@@ -158,12 +158,32 @@ class _Mesh_Arrays():
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)
More information about the Bf-extensions-cvs
mailing list