op: tolerate incomplete macros

Before this change, a macro not Stop'ed would result in an endless
loop during op decoding.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-10-04 17:11:35 -06:00
parent 24eb1a4fc5
commit 80196f3c3e
2 changed files with 23 additions and 1 deletions
+16
View File
@@ -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")
}
}