Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano <germano.costa@ig.com.br>2017-09-10 03:06:57 +0300
committerGermano <germano.costa@ig.com.br>2017-09-10 03:06:57 +0300
commitc4fc81ee4b357425e11ec284d8d1def8e662a0aa (patch)
tree2472b91ae4d13de85cc142666a3c024556a1cb74
parentc5de2c524908ff9efe30bfe6ecd15f3d1f873298 (diff)
Workaround the weird bug "Not freed memory blocks" due GPU_Indices_Mesh
Strange that if you disable the addon before closing the blender, this error message does not appear
-rw-r--r--mesh_snap_utilities_line.py4
-rw-r--r--modules/snap_context/__init__.py25
-rw-r--r--modules/snap_context/mesh_drawing.py24
-rw-r--r--modules/snap_context/utils_shader.py2
4 files changed, 33 insertions, 22 deletions
diff --git a/mesh_snap_utilities_line.py b/mesh_snap_utilities_line.py
index c5e9a825..f582c701 100644
--- a/mesh_snap_utilities_line.py
+++ b/mesh_snap_utilities_line.py
@@ -52,8 +52,6 @@ from bpy.props import (
StringProperty,
)
-from snap_context import SnapContext
-
##DEBUG = False
##if DEBUG:
## from .snap_framebuffer_debug import screenTexture
@@ -907,6 +905,8 @@ class SnapUtilitiesLine(Operator):
self.outer_verts = preferences.outer_verts
self.snap_to_grid = preferences.increments_grid
+ from snap_context import SnapContext
+
self.sctx = SnapContext(context.region, context.space_data)
self.sctx.set_pixel_dist(12)
self.sctx.use_clip_planes(True)
diff --git a/modules/snap_context/__init__.py b/modules/snap_context/__init__.py
index 4767862f..f58cec3c 100644
--- a/modules/snap_context/__init__.py
+++ b/modules/snap_context/__init__.py
@@ -15,13 +15,19 @@
#
# ##### END GPL LICENSE BLOCK #####
+
import bgl
import gpu
from mathutils import Vector, Matrix
from mathutils.geometry import intersect_point_line, intersect_ray_tri
-from .bgl_ext import VoidBufValue, get_clip_planes
-from .mesh_drawing import GPU_Indices_Mesh, gpu_Indices_enable_state, gpu_Indices_restore_state
+from .mesh_drawing import (
+ gpu_Indices_enable_state,
+ gpu_Indices_restore_state,
+ gpu_Indices_use_clip_planes,
+ gpu_Indices_set_ProjectionMatrix,
+ )
+
from .utils_projection import (
region_2d_to_orig_and_view_vector as _get_ray,
intersect_boundbox_threshold,
@@ -59,6 +65,7 @@ class SnapContext():
self._texture = self._offscreen.color_texture
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._texture)
+ from .bgl_ext import VoidBufValue
NULL = VoidBufValue(0)
bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_R32UI, self.region.width, self.region.height, 0, bgl.GL_RED_INTEGER, bgl.GL_UNSIGNED_INT, NULL.buf)
del NULL
@@ -176,16 +183,7 @@ class SnapContext():
self.proj_mat = Matrix.Identity(4)
def use_clip_planes(self, value):
- planes = get_clip_planes(self.rv3d)
- if planes:
- self._store_current_shader_state()
- GPU_Indices_Mesh.shader
- bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
- bgl.glUniform1i(GPU_Indices_Mesh.unif_use_clip_planes, value)
-
- bgl.glUniform4fv(GPU_Indices_Mesh.unif_clip_plane, 4, planes)
-
- self._restore_shader_state()
+ gpu_Indices_use_clip_planes(self.rv3d, value)
def set_pixel_dist(self, dist_px):
self._dist_px = int(dist_px)
@@ -238,7 +236,7 @@ class SnapContext():
proj_mat = self.rv3d.perspective_matrix.copy()
if self.proj_mat != proj_mat:
self.proj_mat = proj_mat
- GPU_Indices_Mesh.set_ProjectionMatrix(self.proj_mat)
+ gpu_Indices_set_ProjectionMatrix(self.proj_mat)
self.update_all()
ray_dir, ray_orig = self.get_ray(mval)
@@ -261,6 +259,7 @@ class SnapContext():
if in_threshold:
if len(snap_obj.data) == 1:
+ from .mesh_drawing import GPU_Indices_Mesh
snap_obj.data.append(GPU_Indices_Mesh(obj, snap_face, snap_edge, snap_vert))
snap_obj.data[1].set_draw_mode(snap_face, snap_edge, snap_vert)
snap_obj.data[1].set_ModelViewMatrix(snap_obj.mat)
diff --git a/modules/snap_context/mesh_drawing.py b/modules/snap_context/mesh_drawing.py
index f7087b16..feecfa7c 100644
--- a/modules/snap_context/mesh_drawing.py
+++ b/modules/snap_context/mesh_drawing.py
@@ -21,7 +21,7 @@ import bmesh
import numpy as np
from mathutils import Matrix
-from .bgl_ext import VoidBufValue, np_array_as_bgl_Buffer, bgl_Buffer_reshape
+from .bgl_ext import VoidBufValue, np_array_as_bgl_Buffer, bgl_Buffer_reshape, get_clip_planes
from .utils_shader import Shader
@@ -349,11 +349,6 @@ class GPU_Indices_Mesh():
self.draw_verts = draw_verts and self.vbo_verts
- @classmethod
- def set_ProjectionMatrix(cls, P):
- cls.P[:] = P
-
-
def set_ModelViewMatrix(self, MV):
self.MV[:] = MV[:]
self.MVP[:] = Matrix(self.P) * MV
@@ -500,6 +495,23 @@ def gpu_Indices_enable_state():
bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
#bgl.glBindVertexArray(GPU_Indices_Mesh.vao[0])
+
def gpu_Indices_restore_state():
bgl.glBindVertexArray(0)
_restore_shader_state(PreviousGLState)
+
+
+def gpu_Indices_use_clip_planes(rv3d, value):
+ planes = get_clip_planes(rv3d)
+ if planes:
+ _store_current_shader_state()
+ bgl.glUseProgram(GPU_Indices_Mesh.shader.program)
+ bgl.glUniform1i(GPU_Indices_Mesh.unif_use_clip_planes, value)
+
+ bgl.glUniform4fv(GPU_Indices_Mesh.unif_clip_plane, 4, planes)
+
+ _restore_shader_state()
+
+
+def gpu_Indices_set_ProjectionMatrix(P):
+ GPU_Indices_Mesh.P[:] = P
diff --git a/modules/snap_context/utils_shader.py b/modules/snap_context/utils_shader.py
index 7a664ad6..ef47dd09 100644
--- a/modules/snap_context/utils_shader.py
+++ b/modules/snap_context/utils_shader.py
@@ -82,4 +82,4 @@ class Shader():
bgl.glDetachShader(self.program, shad)
bgl.glDeleteShader(shad)
bgl.glDeleteProgram(self.program)
- print('shader_del')
+ #print('shader_del')