[Bf-blender-cvs] [4d339f56fe0] master: Fix T55278: Lightmap Pack > New Image broken when active object is None

Philipp Oeser noreply at git.blender.org
Mon Jun 11 11:03:43 CEST 2018


Commit: 4d339f56fe04affc32ad5849fbe3fd395146e515
Author: Philipp Oeser
Date:   Mon Jun 11 11:00:19 2018 +0200
Branches: master
https://developer.blender.org/rB4d339f56fe04affc32ad5849fbe3fd395146e515

Fix T55278: Lightmap Pack > New Image broken when active object is None

thanx bblanimation (Christopher Gearhart) for spotting the issue and
providing the fix!

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D3449

===================================================================

M	release/scripts/startup/bl_operators/uvcalc_lightmap.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/uvcalc_lightmap.py b/release/scripts/startup/bl_operators/uvcalc_lightmap.py
index b8ea642dd55..3757a466382 100644
--- a/release/scripts/startup/bl_operators/uvcalc_lightmap.py
+++ b/release/scripts/startup/bl_operators/uvcalc_lightmap.py
@@ -556,12 +556,24 @@ def lightmap_uvpack(meshes,
 
 def unwrap(operator, context, **kwargs):
 
-    is_editmode = (context.object.mode == 'EDIT')
+    # only unwrap active object if True
+    PREF_ACT_ONLY = kwargs.pop("PREF_ACT_ONLY")
+
+    # ensure object(s) are selected if necessary and active object is set
+    if context.object is None:
+        if PREF_ACT_ONLY:
+            operator.report({'WARNING'}, "Active object not set")
+            return {'CANCELLED'}
+        elif len(context.selected_objects) == 0:
+            operator.report({'WARNING'}, "No selected objects")
+            return {'CANCELLED'}
+
+     # switch to object mode
+    is_editmode = context.object and context.object.mode == 'EDIT'
     if is_editmode:
         bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
 
-    PREF_ACT_ONLY = kwargs.pop("PREF_ACT_ONLY")
-
+    # define list of meshes
     meshes = []
     if PREF_ACT_ONLY:
         obj = context.scene.objects.active
@@ -576,6 +588,7 @@ def unwrap(operator, context, **kwargs):
 
     lightmap_uvpack(meshes, **kwargs)
 
+    # switch back to edit mode
     if is_editmode:
         bpy.ops.object.mode_set(mode='EDIT', toggle=False)



More information about the Bf-blender-cvs mailing list