[Bf-blender-cvs] [9e82499d2d1] blender2.8: Fix T59347: Crash drawing empty image

Campbell Barton noreply at git.blender.org
Fri Dec 14 04:14:09 CET 2018


Commit: 9e82499d2d1ce6b17999b9cb0bc9feb9499a8eaf
Author: Campbell Barton
Date:   Fri Dec 14 14:07:56 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB9e82499d2d1ce6b17999b9cb0bc9feb9499a8eaf

Fix T59347: Crash drawing empty image

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

M	source/blender/draw/modes/object_mode.c

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

diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index f25ca72a799..179726de7ab 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -827,14 +827,12 @@ static DRWShadingGroup *shgroup_theme_id_to_point_or(
 	}
 }
 
-static void image_calc_aspect(Image *ima, ImageUser *iuser, float r_image_aspect[2])
+static void image_calc_aspect(Image *ima, const int size[2], float r_image_aspect[2])
 {
 	float ima_x, ima_y;
 	if (ima) {
-		int w, h;
-		BKE_image_get_size(ima, iuser, &w, &h);
-		ima_x = w;
-		ima_y = h;
+		ima_x = size[0];
+		ima_y = size[1];
 	}
 	else {
 		/* if no image, make it a 1x1 empty square, honor scale & offset */
@@ -871,12 +869,24 @@ static void DRW_shgroup_empty_image(
 	if (!BKE_object_empty_image_is_visible_in_view3d(ob, rv3d))
 		return;
 
-	GPUTexture *tex = ob->data ?
-	        GPU_texture_from_blender(ob->data, ob->iuser, GL_TEXTURE_2D, false, 0.0f) :
-	        NULL;
+	/* Calling 'BKE_image_get_size' may free the texture. Get the size from 'tex' instead, see: T59347 */
+	int size[2] = {0};
+
+	GPUTexture *tex = NULL;
+
+	if (ob->data != NULL) {
+		tex = GPU_texture_from_blender(ob->data, ob->iuser, GL_TEXTURE_2D, false, 0.0f);
+		if (tex) {
+			size[0] = GPU_texture_width(tex);
+			size[1] = GPU_texture_height(tex);
+		}
+	}
+
+	CLAMP_MIN(size[0], 1);
+	CLAMP_MIN(size[1], 1);
 
 	float image_aspect[2];
-	image_calc_aspect(ob->data, ob->iuser, image_aspect);
+	image_calc_aspect(ob->data, size, image_aspect);
 
 	/* OPTI(fclem) We need sorting only for transparent images. If an image as no alpha channel and
 	 * ob->col[3] == 1.0f,  we could remove it from the sorting pass. */



More information about the Bf-blender-cvs mailing list