diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index 0809e8dda6d..4719ec6bae9 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -144,7 +144,9 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref) Main *bmain = user_data; ListBase *lb = which_libbase(bmain, GS(id_ref->name)); LISTBASE_FOREACH (ID *, id, lb) { - if (STREQ(id_ref->name, id->name) && (id->lib == NULL)) { + /* Allow for undoing painting on linked images. */ + const bool is_image = (GS(id_ref->name) == ID_IM); + if (STREQ(id_ref->name, id->name) && (id->lib == NULL || is_image)) { id_ref->ptr = id; break; } diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c index 27b84307f7d..5215b714dec 100644 --- a/source/blender/editors/space_image/image_undo.c +++ b/source/blender/editors/space_image/image_undo.c @@ -544,7 +544,11 @@ static void uhandle_restore_list(ListBase *undo_handles, bool use_init) LISTBASE_FOREACH (UndoImageHandle *, uh, undo_handles) { /* Tiles only added to second set of tiles. */ Image *image = uh->image_ref.ptr; - + /* Prevent crash undoing painting on linked images. */ + if (image == NULL) { + CLOG_ERROR(&LOG, "Unable to get image for UndoImageHandle '%s' (might be linked data?)", uh->image_ref.name); + continue; + } ImBuf *ibuf = BKE_image_acquire_ibuf(image, &uh->iuser, NULL); if (UNLIKELY(ibuf == NULL)) { CLOG_ERROR(&LOG, "Unable to get buffer for image '%s'", image->id.name + 2);