mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
ui: add checks for unmatched Ops.Begin/End
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -2,6 +2,8 @@ package ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"gioui.org/ui/internal/ops"
|
"gioui.org/ui/internal/ops"
|
||||||
)
|
)
|
||||||
@@ -119,6 +121,9 @@ func (op *opBlockDef) decode(data []byte) {
|
|||||||
// End the most recent block and return
|
// End the most recent block and return
|
||||||
// an op for invoking the completed block.
|
// an op for invoking the completed block.
|
||||||
func (o *Ops) End() BlockOp {
|
func (o *Ops) End() BlockOp {
|
||||||
|
if len(o.stack) == 0 {
|
||||||
|
panic(errors.New("End with no matching Begin"))
|
||||||
|
}
|
||||||
start := o.stack[len(o.stack)-1]
|
start := o.stack[len(o.stack)-1]
|
||||||
o.stack = o.stack[:len(o.stack)-1]
|
o.stack = o.stack[:len(o.stack)-1]
|
||||||
pc := o.ops.pc()
|
pc := o.ops.pc()
|
||||||
@@ -219,6 +224,9 @@ func (b BlockOp) Add(o *Ops) {
|
|||||||
|
|
||||||
// Reset start reading from the op list.
|
// Reset start reading from the op list.
|
||||||
func (r *OpsReader) Reset(ops *Ops) {
|
func (r *OpsReader) Reset(ops *Ops) {
|
||||||
|
if n := len(ops.stack); n > 0 {
|
||||||
|
panic(fmt.Errorf("%d Begin(s) not matched with End", n))
|
||||||
|
}
|
||||||
r.ops = &ops.ops
|
r.ops = &ops.ops
|
||||||
r.stack = r.stack[:0]
|
r.stack = r.stack[:0]
|
||||||
r.pc = pc{}
|
r.pc = pc{}
|
||||||
|
|||||||
Reference in New Issue
Block a user