Files
aego/editor/core/code/volatile_states.go
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

113 lines
3.4 KiB
Go

package code
import (
"bytes"
"context"
"errors"
"fmt"
)
// ValidateVolatileStates visits current and Undo/Redo pairs using bounded, cancellable copies on the owner thread; callbacks must not mutate d, and adoption requires identity, revision, source, disk and consent checks.
func (d *Doc) ValidateVolatileStates(ctx context.Context, validate func(text, value []byte) error) error {
if ctx == nil || d == nil || d.buf == nil || d.idx == nil || d.volatile == nil ||
d.batch != nil || d.rev >= maxVolatileJournalRevision || d.Len() > maxVolatileJournalTextBytes ||
len(d.volatile.current) > maxVolatileBytes || len(d.undo)+len(d.redo) > historyLimit || validate == nil {
return errVolatileJournal
}
if err := ctx.Err(); err != nil {
return err
}
rev, saved, selection, glsl, volatile := d.rev, d.saved, d.Sel, d.GLSL, d.volatile
unchanged := func() bool {
return d.rev == rev && d.saved == saved && d.Sel == selection && d.GLSL == glsl &&
d.volatile == volatile && d.batch == nil
}
text, value := d.Bytes(), bytes.Clone(volatile.current)
if err := validateVolatileJournal(ctx, text, value, selection, d.undo, d.redo); err != nil {
return err
}
undo, err := cloneVolatileGroups(ctx, d.undo)
if err != nil {
return err
}
redo, err := cloneVolatileGroups(ctx, d.redo)
if err != nil {
return err
}
if !unchanged() {
return errors.New("document changed during volatile state validation")
}
// Bound retained callback copies separately from replay work.
remainingCopies := int64(maxVolatileJournalBytes)
remainingReplay := int64(maxVolatileJournalReplayBytes)
visit := func(text, value []byte) error {
if err := ctx.Err(); err != nil {
return err
}
if !unchanged() {
return errors.New("document changed during volatile state validation")
}
cost := int64(len(text)) + int64(len(value))
if cost > remainingCopies {
return errVolatileJournal
}
remainingCopies -= cost
err := validate(bytes.Clone(text), bytes.Clone(value))
if !unchanged() {
return errors.New("document changed during volatile state validation")
}
if canceled := ctx.Err(); canceled != nil {
return canceled
}
if err != nil {
return fmt.Errorf("volatile state validation: %w", err)
}
return nil
}
if err := visit(text, value); err != nil {
return err
}
for _, branch := range []struct {
groups []group
undo bool
}{{undo, true}, {redo, false}} {
currentText, currentValue := text, value
for i := len(branch.groups) - 1; i >= 0; i-- {
if err := ctx.Err(); err != nil {
return err
}
g := branch.groups[i]
if g.volatile {
want, next := g.volatileBefore, g.volatileAfter
if branch.undo {
want, next = next, want
}
cost := int64(len(currentValue)) + int64(len(want))
if cost > remainingReplay || !bytes.Equal(currentValue, want) {
return errVolatileJournal
}
remainingReplay -= cost
currentValue = next
} else if branch.undo {
for j := len(g.recs) - 1; j >= 0; j-- {
currentText, err = replayVolatileRecord(ctx, currentText, g.recs[j], true, &remainingReplay)
if err != nil {
return err
}
}
} else {
for _, rec := range g.recs {
currentText, err = replayVolatileRecord(ctx, currentText, rec, false, &remainingReplay)
if err != nil {
return err
}
}
}
if err := visit(currentText, currentValue); err != nil {
return err
}
}
}
return nil
}