Fix T99340: Image.frame_duration returning wrong value when image not loaded

The logic here was broken in d5f1b9c, it should load the image first.
This commit is contained in:
Brecht Van Lommel 2022-07-20 18:19:37 +02:00
parent c4d8e28aa7
commit 5d4574ea0e
Notes: blender-bot 2023-02-14 10:11:49 +01:00
Referenced by issue #99340, IMB_anim_get_duration no valid after undo if animation is playing
1 changed files with 7 additions and 6 deletions

View File

@ -475,18 +475,19 @@ static int rna_Image_frame_duration_get(PointerRNA *ptr)
Image *ima = (Image *)ptr->owner_id;
int duration = 1;
if (!BKE_image_has_anim(ima)) {
/* Ensure image has been loaded into memory and frame duration is known. */
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
BKE_image_release_ibuf(ima, ibuf, lock);
}
if (BKE_image_has_anim(ima)) {
struct anim *anim = ((ImageAnim *)ima->anims.first)->anim;
if (anim) {
duration = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN);
}
}
else {
/* acquire ensures ima->anim is set, if possible! */
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
BKE_image_release_ibuf(ima, ibuf, lock);
}
return duration;
}