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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-12-14 06:07:56 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-12-14 06:13:59 +0300
commit9e82499d2d1ce6b17999b9cb0bc9feb9499a8eaf (patch)
tree7228a7f38005e55d5b0136628fb343d35502758e /source/blender
parentfb685c01c31688b8edb1914336eac2f318e262ec (diff)
Fix T59347: Crash drawing empty image
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/draw/modes/object_mode.c28
1 files changed, 19 insertions, 9 deletions
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. */