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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user