From 4d339f56fe04affc32ad5849fbe3fd395146e515 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Mon, 11 Jun 2018 11:00:19 +0200 Subject: [PATCH 1/2] 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 --- .../startup/bl_operators/uvcalc_lightmap.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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) From 28c34ae7e2d61d0b1c570b7d9a303267404e54be Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 11 Jun 2018 11:05:24 +0200 Subject: [PATCH 2/2] Cleanup: Use BLI_strncpy It has behavior which we expect, and silences strict compiler warning. --- source/blender/blenkernel/intern/suggestions.c | 4 ++-- source/blender/blenkernel/intern/text.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c index eb17e103671..b74143b5c07 100644 --- a/source/blender/blenkernel/intern/suggestions.c +++ b/source/blender/blenkernel/intern/suggestions.c @@ -246,12 +246,12 @@ void texttool_docs_show(const char *docs) /* Ensure documentation ends with a '\n' */ if (docs[len - 1] != '\n') { documentation = MEM_mallocN(len + 2, "Documentation"); - strncpy(documentation, docs, len); + BLI_strncpy(documentation, docs, len); documentation[len++] = '\n'; } else { documentation = MEM_mallocN(len + 1, "Documentation"); - strncpy(documentation, docs, len); + BLI_strncpy(documentation, docs, len); } documentation[len] = '\0'; } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bd2afd0c512..eed3138ec1b 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1705,7 +1705,7 @@ static void txt_undo_add_blockop(Text *text, TextUndoBuf *utxt, int op, const ch /* 4 bytes */ txt_undo_store_uint32(utxt->buf, &utxt->pos, length); /* 'length' bytes */ - strncpy(utxt->buf + utxt->pos, buf, length); + BLI_strncpy(utxt->buf + utxt->pos, buf, length); utxt->pos += length; /* 4 bytes */ txt_undo_store_uint32(utxt->buf, &utxt->pos, length);