diff options
author | Jacques Lucke <jacques@blender.org> | 2021-11-23 11:44:04 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-11-23 11:44:04 +0300 |
commit | f6573560623606301d6e249032f42ca47ae438eb (patch) | |
tree | caa3dd7b8bc1eee1cb516870e2c4a3836bfdf5d9 /source/blender/blenkernel/intern | |
parent | 28870a8f890b503c7dd5df9f949fc7030d56e8e4 (diff) | |
parent | b02ac2d8be38d198edfece7347919d67f7cc7275 (diff) |
Merge branch 'blender-v3.0-release'
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 51 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.cc | 9 |
2 files changed, 45 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index c0efc246567..1ef5659855b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -4233,13 +4233,16 @@ static int image_num_files(Image *ima) return BLI_listbase_count(&ima->views); } -static ImBuf *load_sequence_single(Image *ima, ImageUser *iuser, int frame, const int view_id) +static ImBuf *load_sequence_single( + Image *ima, ImageUser *iuser, int frame, const int view_id, bool *r_cache_ibuf) { struct ImBuf *ibuf; char name[FILE_MAX]; int flag; ImageUser iuser_t = {0}; + *r_cache_ibuf = true; + ima->lastframe = frame; if (iuser) { @@ -4279,6 +4282,9 @@ static ImBuf *load_sequence_single(Image *ima, ImageUser *iuser, int frame, cons ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); ibuf = NULL; + /* NULL ibuf in the cache means the image failed to load. However for multilayer we load + * pixels into RenderResult instead and intentionally leave ibuf NULL. */ + *r_cache_ibuf = false; } } else { @@ -4299,17 +4305,21 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, const int totfiles = image_num_files(ima); if (!is_multiview) { - ibuf = load_sequence_single(ima, iuser, frame, 0); - image_assign_ibuf(ima, ibuf, 0, entry); + bool put_in_cache; + ibuf = load_sequence_single(ima, iuser, frame, 0, &put_in_cache); + if (put_in_cache) { + image_assign_ibuf(ima, ibuf, 0, entry); + } } else { const int totviews = BLI_listbase_count(&ima->views); struct ImBuf **ibuf_arr; ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); + bool *cache_ibuf_arr = MEM_mallocN(sizeof(bool) * totviews, "Image View Put In Cache"); for (int i = 0; i < totfiles; i++) { - ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i); + ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, cache_ibuf_arr + i); } if (BKE_image_is_stereo(ima) && ima->views_format == R_IMF_VIEWS_STEREO_3D) { @@ -4320,7 +4330,9 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; for (int i = 0; i < totviews; i++) { - image_assign_ibuf(ima, ibuf_arr[i], i, entry); + if (cache_ibuf_arr[i]) { + image_assign_ibuf(ima, ibuf_arr[i], i, entry); + } } /* "remove" the others (decrease their refcount) */ @@ -4332,6 +4344,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, /* cleanup */ MEM_freeN(ibuf_arr); + MEM_freeN(cache_ibuf_arr); } return ibuf; @@ -4493,13 +4506,19 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) return ibuf; } -static ImBuf *load_image_single( - Image *ima, ImageUser *iuser, int cfra, const int view_id, const bool has_packed) +static ImBuf *load_image_single(Image *ima, + ImageUser *iuser, + int cfra, + const int view_id, + const bool has_packed, + bool *r_cache_ibuf) { char filepath[FILE_MAX]; struct ImBuf *ibuf = NULL; int flag; + *r_cache_ibuf = true; + /* is there a PackedFile with this image ? */ if (has_packed) { ImagePackedFile *imapf; @@ -4550,6 +4569,9 @@ static ImBuf *load_image_single( ima->type = IMA_TYPE_MULTILAYER; IMB_freeImBuf(ibuf); ibuf = NULL; + /* NULL ibuf in the cache means the image failed to load. However for multilayer we load + * pixels into RenderResult instead and intentionally leave ibuf NULL. */ + *r_cache_ibuf = false; } } else @@ -4594,8 +4616,11 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } if (!is_multiview) { - ibuf = load_image_single(ima, iuser, cfra, 0, has_packed); - image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); + bool put_in_cache; + ibuf = load_image_single(ima, iuser, cfra, 0, has_packed, &put_in_cache); + if (put_in_cache) { + image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); + } } else { struct ImBuf **ibuf_arr; @@ -4603,9 +4628,10 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) BLI_assert(totviews > 0); ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); + bool *cache_ibuf_arr = MEM_mallocN(sizeof(bool) * totviews, "Image Views Put In Cache"); for (int i = 0; i < totfiles; i++) { - ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed); + ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, cache_ibuf_arr + i); } /* multi-views/multi-layers OpenEXR files directly populate ima, and return NULL ibuf... */ @@ -4619,7 +4645,9 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) ibuf = ibuf_arr[i]; for (i = 0; i < totviews; i++) { - image_assign_ibuf(ima, ibuf_arr[i], i, 0); + if (cache_ibuf_arr[i]) { + image_assign_ibuf(ima, ibuf_arr[i], i, 0); + } } /* "remove" the others (decrease their refcount) */ @@ -4631,6 +4659,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) /* cleanup */ MEM_freeN(ibuf_arr); + MEM_freeN(cache_ibuf_arr); } return ibuf; diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index d650003afe2..b2dd4b40bae 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -4573,10 +4573,11 @@ Mesh *BKE_object_get_evaluated_mesh(const Object *object) * object types either store it there or add a reference to it if it's owned elsewhere. */ GeometrySet *geometry_set_eval = object->runtime.geometry_set_eval; if (geometry_set_eval) { - /* Some areas expect to be able to modify the evaluated mesh. Theoretically this should be - * avoided, or at least protected with a lock, so a const mesh could be returned from this - * function. */ - Mesh *mesh = geometry_set_eval->get_mesh_for_write(); + /* Some areas expect to be able to modify the evaluated mesh in limited ways. Theoretically + * this should be avoided, or at least protected with a lock, so a const mesh could be returned + * from this function. We use a const_cast instead of #get_mesh_for_write, because that might + * result in a copy of the mesh when it is shared. */ + Mesh *mesh = const_cast<Mesh *>(geometry_set_eval->get_mesh_for_read()); if (mesh) { return mesh; } |