{"record":{"id":"c6c7d862d7858cce","repo":"stride3d/stride","slug":"unable-to-clear-a-rollback-or-rollforward-operation-is-in","errorCode":null,"errorMessage":"Unable to clear. A rollback or rollforward operation is in progress.","messagePattern":"Unable to clear\\. A rollback or rollforward operation is in progress\\.","errorType":"exception","errorClass":"TransactionException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Transactions/TransactionStack.cs","lineNumber":114,"sourceCode":"        {\n            if (transactionsInProgress.Count == 0)\n                throw new TransactionException(\"There is no transaction in progress in the transaction stack.\");\n\n            if (!operation.HasEffect)\n                return;\n\n            var transaction = transactionsInProgress.Peek();\n            transaction.PushOperation(operation);\n        }\n    }\n\n    /// <inheritdoc/>\n    public void Clear()\n    {\n        lock (lockObject)\n        {\n            if (RollInProgress)\n                throw new TransactionException(\"Unable to clear. A rollback or rollforward operation is in progress.\");\n\n            foreach (var transaction in transactions)\n            {\n                transaction.Interface.Freeze();\n            }\n            transactions.Clear();\n            currentPosition = 0;\n            Cleared?.Invoke(this, EventArgs.Empty);\n        }\n    }\n\n    /// <inheritdoc/>\n    public IEnumerable<IReadOnlyTransaction> RetrieveAllTransactions()\n    {\n        return transactions;\n    }\n\n    public void CompleteTransaction(Transaction transaction)","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Transactions/TransactionStack.cs#L96-L132","documentation":"TransactionStack.Clear() wipes all transactions from the undo/redo history, but it must not run while a rollback or rollforward is executing, because Clear would mutate the transaction list the rollback/rollforward loop is iterating. The stack throws this error when Clear is called while RollInProgress is true.","triggerScenarios":"Calling transactionStack.Clear() from inside a transaction's Rollback() or Rollforward() handler, or from another thread while a rollback/rollforward is running.","commonSituations":"Undo/redo callbacks that try to reset history; UI event handlers firing Clear while a rollback animation/operation is still in flight; re-entrant calls during Rollback/Rollforward.","solutions":["Defer Clear() until after the rollback/rollforward completes (e.g. queue it and run after Rollback returns).","Remove the Clear call from any code executed inside transaction rollback/rollforward handlers.","If Clear is triggered by events, check a RollInProgress flag on the stack before calling Clear.","Synchronize cross-thread calls so Clear and Rollback never overlap."],"exampleFix":"// before\nvoid OnHistoryResetRequested() => stack.Clear();\n\n// after\nvoid OnHistoryResetRequested()\n{\n    if (!stack.RollInProgress)\n        stack.Clear();\n    else\n        pendingClear = true; // clear after rollback finishes\n}","handlingStrategy":"validation","validationCode":"if (transactionStack.RollInProgress)\n    throw new InvalidOperationException(\"Cannot clear history during rollback/rollforward.\");\ntransactionStack.Clear();","typeGuard":"bool CanClearHistory(TransactionStack stack) => !stack.RollInProgress;","tryCatchPattern":"try\n{\n    transactionStack.Clear();\n}\ncatch (TransactionException ex) when (ex.Message.Contains(\"rollback or rollforward\"))\n{\n    // retry after the roll operation completes\n}","preventionTips":["Never call Clear from inside rollback/rollforward handlers.","Queue Clear requests and execute them after roll operations finish.","Serialize stack mutations onto a single thread."],"tags":["transactions","undo-redo","reentrancy"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}