diff --git a/internal/ops/reader.go b/internal/ops/reader.go index 7e212dfb..394bfcc9 100644 --- a/internal/ops/reader.go +++ b/internal/ops/reader.go @@ -150,7 +150,13 @@ func (r *Reader) Decode() (EncodedOp, bool) { case TypeMacro: var op opMacroDef op.decode(data) - r.pc = op.endpc + if op.endpc != (PC{}) { + r.pc = op.endpc + } else { + // Treat an incomplete macro as containing all remaining ops. + r.pc.data = len(r.ops.data) + r.pc.refs = len(r.ops.refs) + } continue } r.pc.data += n diff --git a/op/op_test.go b/op/op_test.go index 2e3d9b55..9f31053f 100644 --- a/op/op_test.go +++ b/op/op_test.go @@ -5,6 +5,8 @@ package op import ( "image" "testing" + + "gioui.org/internal/ops" ) func TestTransformChecks(t *testing.T) { @@ -18,3 +20,17 @@ func TestTransformChecks(t *testing.T) { Record(&ops) trans.Pop() } + +func TestIncompleteMacroReader(t *testing.T) { + var o Ops + // Record, but don't Stop it. + Record(&o) + Offset(image.Point{}).Push(&o) + + var r ops.Reader + + r.Reset(&o.Internal) + if _, more := r.Decode(); more { + t.Error("decoded an operation from a semantically empty Ops") + } +}