View Single Post
Old 06-25-2019, 07:28 PM   #1
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 1,619
Default Deeply confused about JSFX serialization and undo (bug?)

Suppose you:
  1. have a JSFX that maintains and serializes an internal variable
  2. have a Lua script that adjusts a parameter on the JSFX within an Undo block
  3. execute the Lua script action
  4. undo the action via ctrl-z

Expected result: after the undo, the internal (serialized) variable should be restored to its value at the moment of Undo_BeginBlock2()

Actual result: after the undo, the internal variable is restored to the value it had roughly at instantiation time.

Attached is an example JSFX and Lua action that demonstrates this.

The attached JSFX maintains a counter that increments inside @block. The counter is read and written in @serialize.

At first initialization:



This is a fresh instance. We see no attempts to deserialize (given that there's nothing to deserialize), with 2 serializations, where the value of the counter at the time of last serialization was 2 (i.e. two executions of @block).

Now I execute the attached Lua script action, which increments the control slider value within an undo block:



By the time I got around to executing the action, the counter had run up to 5653. This was the value of the counter during last serialization, and we can see the number of serializations has increased by 1. Makes sense. And the control slider has incremented by 1, which is what the action does within the undo block.

And the action in appears as expected in the undo history:



But now when I undo the action with ctrl-z, this is the result:



We see the number of deserializations has increased, which is expected as the undo action will deserialize the previous serialized state. However, notice the last read value wasn't the last written value (or at least the value of the counter at last serialization -- I can't be certain what was actually written): it was the value of counter at the previous serialization time (i.e. 2).

The control slider has returned to its original state as expected, but the internal serialized counter variable was restored to the value not at the time of Undo_BeginBlock2() but rather at a moment much earlier, closer to the time it was initially instantiated.

Can someone help me make sense of this? I'm afraid I'm in need of a cluebatting.

Much obliged.
Attached Files
File Type: lua Test Serialize.lua (407 Bytes, 126 views)
File Type: txt Serialize Test.jsfx.txt (1.0 KB, 120 views)

Last edited by tack; 06-25-2019 at 07:37 PM.
tack is offline   Reply With Quote