[Bf-extensions-cvs] [4e8b24c6] master: Cursor Control: Fix crash with poll
lijenstina
noreply at git.blender.org
Wed Jul 12 21:28:18 CEST 2017
Commit: 4e8b24c6c443e280917f4ac37711a52bdef9718e
Author: lijenstina
Date: Wed Jul 12 21:27:35 2017 +0200
Branches: master
https://developer.blender.org/rBAC4e8b24c6c443e280917f4ac37711a52bdef9718e
Cursor Control: Fix crash with poll
Bumped version to 0.7.3
Fix a possible crash in CursorAccess class when
findSpace returns None - if the 3d view is not found
Since the code is called in the poll it can possibly
break on reload
Remove an unused variable
===================================================================
M space_view3d_cursor_control/__init__.py
M space_view3d_cursor_control/cursor_utils.py
M space_view3d_cursor_control/data.py
M space_view3d_cursor_control/history.py
M space_view3d_cursor_control/memory.py
M space_view3d_cursor_control/operators.py
===================================================================
diff --git a/space_view3d_cursor_control/__init__.py b/space_view3d_cursor_control/__init__.py
index 822736fd..f6b8e7c3 100644
--- a/space_view3d_cursor_control/__init__.py
+++ b/space_view3d_cursor_control/__init__.py
@@ -20,7 +20,7 @@
bl_info = {
"name": "Cursor Control",
"author": "Morgan Mörtsell (Seminumerical)",
- "version": (0, 7, 2),
+ "version": (0, 7, 3),
"blender": (2, 65, 4),
"location": "View3D > Properties > Cursor",
"description": "Control the Cursor",
diff --git a/space_view3d_cursor_control/cursor_utils.py b/space_view3d_cursor_control/cursor_utils.py
index c8a34506..f91611e2 100644
--- a/space_view3d_cursor_control/cursor_utils.py
+++ b/space_view3d_cursor_control/cursor_utils.py
@@ -47,9 +47,12 @@ class CursorAccess:
@classmethod
def setCursor(cls, coordinates):
spc = cls.findSpace()
- spc.cursor_location = coordinates
+ try:
+ spc.cursor_location = coordinates
+ except:
+ pass
@classmethod
def getCursor(cls):
spc = cls.findSpace()
- return spc.cursor_location
+ return spc.cursor_location if spc else None
diff --git a/space_view3d_cursor_control/data.py b/space_view3d_cursor_control/data.py
index c31c2687..d96720e8 100644
--- a/space_view3d_cursor_control/data.py
+++ b/space_view3d_cursor_control/data.py
@@ -78,7 +78,7 @@ class CursorControlData(PropertyGroup):
def setCursor(self, v):
if self.stepLengthEnable:
c = CursorAccess.getCursor()
- if((Vector(c) - Vector(v)).length > 0):
+ if c and ((Vector(c) - Vector(v)).length > 0):
if self.stepLengthMode == 'Absolute':
v = Vector(v) - Vector(c)
v.normalize()
@@ -112,8 +112,10 @@ class CursorControlData(PropertyGroup):
def addDeltaVectorToCursor(self):
c = CursorAccess.getCursor()
- CursorAccess.setCursor(Vector(c) + Vector(self.deltaVector))
+ if c:
+ CursorAccess.setCursor(Vector(c) + Vector(self.deltaVector))
def subDeltaVectorToCursor(self):
c = CursorAccess.getCursor()
- CursorAccess.setCursor(Vector(c) - Vector(self.deltaVector))
+ if c:
+ CursorAccess.setCursor(Vector(c) - Vector(self.deltaVector))
diff --git a/space_view3d_cursor_control/history.py b/space_view3d_cursor_control/history.py
index a8eb91a1..dc667ce0 100644
--- a/space_view3d_cursor_control/history.py
+++ b/space_view3d_cursor_control/history.py
@@ -197,8 +197,11 @@ class VIEW3D_PT_cursor_history(Panel):
@classmethod
def poll(self, context):
- # Display in object or edit mode.
+ # Display in object or edit mode
cc = context.scene.cursor_history
+ if CursorAccess.getCursor() is None:
+ return False
+
cc.addHistoryLocation(CursorAccess.getCursor())
if (context.area.type == 'VIEW_3D' and
(context.mode == 'EDIT_MESH' or
@@ -239,7 +242,8 @@ class VIEW3D_PT_cursor_history(Panel):
row = layout.row()
col = row.column()
- col.prop(CursorAccess.findSpace(), "cursor_location")
+ if CursorAccess.findSpace():
+ col.prop(CursorAccess.findSpace(), "cursor_location")
class VIEW3D_PT_cursor_history_init(Panel):
diff --git a/space_view3d_cursor_control/memory.py b/space_view3d_cursor_control/memory.py
index 03d98315..859ce6a1 100644
--- a/space_view3d_cursor_control/memory.py
+++ b/space_view3d_cursor_control/memory.py
@@ -85,6 +85,11 @@ class VIEW3D_OT_cursor_memory_save(Operator):
return {'FINISHED'}
def execute(self, context):
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
cc = context.scene.cursor_memory
cc.savedLocation = CursorAccess.getCursor()
CursorAccess.setCursor(cc.savedLocation)
@@ -101,6 +106,12 @@ class VIEW3D_OT_cursor_memory_swap(Operator):
return {'FINISHED'}
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
location = CursorAccess.getCursor().copy()
cc = context.scene.cursor_memory
CursorAccess.setCursor(cc.savedLocation)
@@ -167,9 +178,9 @@ class VIEW3D_PT_cursor_memory(Panel):
if (context.area.type == 'VIEW_3D' and
(context.mode == 'EDIT_MESH' or
context.mode == 'OBJECT')):
- return 1
+ return True
- return 0
+ return False
def draw_header(self, context):
layout = self.layout
diff --git a/space_view3d_cursor_control/operators.py b/space_view3d_cursor_control/operators.py
index 44bf41a9..4d9a29f3 100644
--- a/space_view3d_cursor_control/operators.py
+++ b/space_view3d_cursor_control/operators.py
@@ -145,6 +145,12 @@ class VIEW3D_OT_cursor_to_sl_mirror(Operator):
cc.setCursor(p + v)
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
obj = context.active_object
cc = context.scene.cursor_control
@@ -225,6 +231,12 @@ class VIEW3D_OT_cursor_to_vertex(Operator):
mati = mat.copy()
mati.invert()
vs = obj.data.vertices
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
c = mati * Vector(CursorAccess.getCursor())
v = None
d = -1
@@ -260,6 +272,12 @@ class VIEW3D_OT_cursor_to_line(Operator):
return {'FINISHED'}
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -315,6 +333,12 @@ class VIEW3D_OT_cursor_to_edge(Operator):
return {'FINISHED'}
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -373,6 +397,12 @@ class VIEW3D_OT_cursor_to_plane(Operator):
return {'FINISHED'}
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -431,6 +461,12 @@ class VIEW3D_OT_cursor_to_face(Operator):
return context.active_object is not None
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -582,6 +618,12 @@ class VIEW3D_OT_cursor_to_cylinderaxis(Operator):
return context.active_object is not None
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -619,6 +661,12 @@ class VIEW3D_OT_cursor_to_spherecenter(Operator):
return context.active_object is not None
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -675,6 +723,12 @@ class VIEW3D_OT_cursor_to_perimeter(Operator):
return context.active_object is not None
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -726,6 +780,12 @@ class VIEW3D_OT_cursor_offset_from_radius(Operator):
return {'FINISHED'}
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Operation Cancelled")
+ return {"CANCELLED"}
+
BlenderFake.forceUpdate()
cc = context.scene.cursor_control
cc.hideLinexChoice()
@@ -833,7 +893,6 @@ class VIEW3D_OT_cursor_stepval_vvdist(Operator):
mat = obj.matrix_world
mati = mat.copy()
mati.invert()
- c = mati * Vector(CursorAccess.getCursor())
sf = [f for f in obj.data.vertices if f.select == 1]
v0 = Vector(sf[0].co)
@@ -924,6 +983,12 @@ class VIEW3D_OT_ccdelta_vvdist(Operator):
return context.active_object is not None
def execute(self, context):
+
+ if CursorAccess.getCursor() is None:
+ self.report({'WARNING'},
+ "Cursor location cannot be retrieved. Ope
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list