diff --git a/op/clip/clip.go b/op/clip/clip.go index 2c070f8d..bc9adcdd 100644 --- a/op/clip/clip.go +++ b/op/clip/clip.go @@ -124,10 +124,12 @@ func (p *Path) Pos() f32.Point { return p.pen } // Begin the path, storing the path data and final Op into ops. func (p *Path) Begin(o *op.Ops) { + *p = Path{ + ops: &o.Internal, + macro: op.Record(o), + contour: 1, + } p.hash.SetSeed(pathSeed) - p.ops = &o.Internal - p.macro = op.Record(o) - // Write the TypeAux opcode data := ops.Write(p.ops, ops.TypeAuxLen) data[0] = byte(ops.TypeAux) } diff --git a/op/clip/clip_test.go b/op/clip/clip_test.go index cc7f1be7..69c06860 100644 --- a/op/clip/clip_test.go +++ b/op/clip/clip_test.go @@ -1,12 +1,16 @@ // SPDX-License-Identifier: Unlicense OR MIT -package clip +package clip_test import ( + "image/color" "testing" "gioui.org/f32" + "gioui.org/gpu/headless" "gioui.org/op" + "gioui.org/op/clip" + "gioui.org/op/paint" ) func TestOpenPathOutlinePanic(t *testing.T) { @@ -15,10 +19,27 @@ func TestOpenPathOutlinePanic(t *testing.T) { t.Error("Outline of an open path didn't panic") } }() - var p Path + var p clip.Path p.Begin(new(op.Ops)) p.Line(f32.Pt(10, 10)) - Outline{Path: p.End()}.Op() + clip.Outline{Path: p.End()}.Op() +} + +func TestPathBegin(t *testing.T) { + ops := new(op.Ops) + var p clip.Path + p.Begin(ops) + p.LineTo(f32.Point{10, 10}) + p.Close() + stack := clip.Outline{Path: p.End()}.Op().Push(ops) + paint.Fill(ops, color.NRGBA{A: 255}) + stack.Pop() + w := newWindow(t, 100, 100) + if w == nil { + return + } + // The following should not panic. + _ = w.Frame(ops) } func TestTransformChecks(t *testing.T) { @@ -28,7 +49,15 @@ func TestTransformChecks(t *testing.T) { } }() var ops op.Ops - st := Op{}.Push(&ops) + st := clip.Op{}.Push(&ops) op.Record(&ops) st.Pop() } + +func newWindow(t testing.TB, width, height int) *headless.Window { + w, err := headless.NewWindow(width, height) + if err != nil { + t.Skipf("failed to create headless window, skipping: %v", err) + } + return w +}