From 270a229728712f2a31ff341eba89b059df6299e4 Mon Sep 17 00:00:00 2001 From: Falk David Date: Thu, 3 Aug 2023 11:11:19 +0200 Subject: [PATCH] Fix: GPv3: Crash on undo when changing frames map Changing the frames map would lead to a crash later in undo. This was because the `frames_storage` was not written to file corectly. When the `frames_storage` was tagged dirty, it recreated the `frames_storage.num` as well as the `keys` and `values` pointers. The `keys` and `values` pointers were written after the update, but since the `num` is just an `int` in the embeded struct, it was written before being updated. This lead to an out-of-sync state and later to the crash. The fix makes sure we write the struct *after* updating it. --- source/blender/blenkernel/intern/grease_pencil.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index 05865c96e90..21a64f0e2a5 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -2055,9 +2055,6 @@ static void write_layer(BlendWriter *writer, GreasePencilLayer *node) { using namespace blender::bke::greasepencil; - BLO_write_struct(writer, GreasePencilLayer, node); - BLO_write_string(writer, node->base.name); - /* Re-create the frames storage only if it was tagged dirty. */ if ((node->frames_storage.flag & GP_LAYER_FRAMES_STORAGE_DIRTY) != 0) { MEM_SAFE_FREE(node->frames_storage.keys); @@ -2078,6 +2075,9 @@ static void write_layer(BlendWriter *writer, GreasePencilLayer *node) node->frames_storage.flag &= ~GP_LAYER_FRAMES_STORAGE_DIRTY; } + BLO_write_struct(writer, GreasePencilLayer, node); + BLO_write_string(writer, node->base.name); + BLO_write_int32_array(writer, node->frames_storage.num, node->frames_storage.keys); BLO_write_struct_array( writer, GreasePencilFrame, node->frames_storage.num, node->frames_storage.values);