Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/Scripts/Commands/MoveWidgetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public MoveWidgetCommand(GrabWidget widget, TrTransform endXf, Vector3 endCustom
}

public override bool NeedsSave { get { return true; } }
public bool IsFinal => m_Final;

protected override void OnRedo()
{
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/Multiplayer/Photon/PhotonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ private bool ProcessCommand(BaseCommand command, PlayerRef playerRef = default)
case SwitchEnvironmentCommand:
success &= CommandSwitchEnvironment(command as SwitchEnvironmentCommand, playerRef);
break;
case MoveWidgetCommand:
var cmd = command as MoveWidgetCommand;
if (cmd.IsFinal)
{
success &= CommandBase(command);
}
Comment on lines +439 to +444
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When cmd.IsFinal is false, the method continues without setting success, but the return value of ProcessCommand depends on success. This could lead to incorrect return values when non-final MoveWidgetCommands are processed. Consider explicitly setting success = true in the else case or restructuring the logic to handle this scenario properly.

Suggested change
case MoveWidgetCommand:
var cmd = command as MoveWidgetCommand;
if (cmd.IsFinal)
{
success &= CommandBase(command);
}
}
else
{
success = true;
}

Copilot uses AI. Check for mistakes.

break;
case BaseCommand:
success &= CommandBase(command);
break;
Expand Down
9 changes: 5 additions & 4 deletions Assets/Scripts/SketchMemoryScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,22 +415,23 @@ public void PerformAndRecordCommand(BaseCommand command, bool discardIfNotMerged
bool discardCommand = discardIfNotMerged;
BaseCommand delta = command;
ClearRedo();
while (m_OperationStack.Any())
while (m_OperationStack.Any()) // Are there any commands on the undo stack?
{
BaseCommand top = m_OperationStack.Pop();
if (!top.Merge(command))
if (!top.Merge(command)) // Have we hit a command we can't merge?
{
m_OperationStack.Push(top);
break;
}
discardCommand = false;
discardCommand = false; // We're still merging
command = top;
}
if (discardCommand)
if (discardCommand) // Something was merged
{
command.Dispose();
return;
}
// Nothing was merged so execute the command
delta.Redo();
m_OperationStack.Push(command);
OperationStackChanged?.Invoke();
Expand Down