M internal/ops/reader.go => internal/ops/reader.go +7 -1
@@ 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
M op/op_test.go => op/op_test.go +16 -0
@@ 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")
+ }
+}