Comment by ~tangyang on ~eliasnaur/gio
I found that the
displayLayer
called afterwindowWillClose
had been called.It's wierd, maybe macos need to draw something after a fullscreen window closed, like the window close animation?
Maybe we can just ignore the ondraw event while "view not found" happend.
app/os_macos.go
//export gio_onDraw func gio_onDraw(view C.CFTypeRef) { w, ok := lookupView(view) if !ok { return } w.draw() }
Ticket created by ~tangyang on ~eliasnaur/gio
System Version: macos 12.6.1
Gio version: gioui.org v0.0.0-20221122135904-dee53b364560
Reproduce Step: Apply full screen, then close the window.
Example code:
package main import ( "flag" "gioui.org/app" "gioui.org/font/gofont" "gioui.org/io/event" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op" "gioui.org/widget/material" ) func main() { flag.Parse() go run() app.Main() } func run() { w := app.NewWindow() var ops op.Ops th := material.NewTheme(gofont.Collection()) for { var e event.Event e = <-w.Events() switch e := e.(type) { case system.DestroyEvent: go run() return case system.FrameEvent: gtx := layout.NewContext(&ops, e) layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(material.Body1(th, string("hello world")).Layout), ) e.Frame(gtx.Ops) } } }
Comment by ~tangyang on ~eliasnaur/gio
I'm writing a video player by using Gio, so lot's of image need to be uploaded to Metal.
I cannot reproduce the crash, maybe we should close this issue until i found a way to reproduce the crash.
Thank you for your help!
Ticket created by ~tangyang on ~eliasnaur/gio
I found that using a combination of label, giox/contextarea, giox/menu can simulate a dropdown menu, but not perfect enough.
I think maybe a official dropdown-menu widget would be a better solution for this.
Comment by ~tangyang on ~eliasnaur/gio
Thank you for your great help!
After using the clip op, everything work well!
package main import ( "fmt" "image" "image/color" "log" "os" "gioui.org/app" "gioui.org/font/gofont" "gioui.org/io/event" "gioui.org/io/pointer" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op" "gioui.org/op/clip" "gioui.org/text" "gioui.org/widget/material" ) func main() { w := app.NewWindow() go func() { th := material.NewTheme(gofont.Collection()) var ops op.Ops l := layout.List{Axis: layout.Vertical} for { var e event.Event e = <-w.Events() switch e := e.(type) { case system.DestroyEvent: os.Exit(0) return case system.FrameEvent: gtx := layout.NewContext(&ops, e) l.Layout(gtx, 100, func(gtx layout.Context, index int) layout.Dimensions { for _, ev := range gtx.Queue.Events(index) { pe, ok := ev.(pointer.Event) if !ok { continue } if pe.Type != pointer.Release { continue } log.Println("clicked", index, pe.Type, pe.Buttons) } label := material.Label(th, 30, fmt.Sprintf("item: #%d", index)) if index%2 == 0 { label.Color = color.NRGBA{A: 255, R: 200} label.Font.Weight = text.Bold } return addEvent(func(gtx layout.Context) layout.Dimensions { return layout.Inset{Top: 10, Left: 10}.Layout(gtx, label.Layout) }, pointer.InputOp{Tag: index, Types: pointer.Release}.Add)(gtx) }) e.Frame(&ops) } } }() app.Main() } func addEvent(w layout.Widget, events func(*op.Ops)) layout.Widget { return func(gtx layout.Context) layout.Dimensions { macro := op.Record(gtx.Ops) dis := w(gtx) c := macro.Stop() rect := clip.Rect{Min: image.Pt(0, 0), Max: dis.Size} defer rect.Op().Push(gtx.Ops).Pop() // add events events(gtx.Ops) c.Add(gtx.Ops) return dis } }
Ticket created by ~tangyang on ~eliasnaur/gio
#Problem description:
I noticed that binding events to items in list works very weird.
#Software Environment
System: macos Monterey 12.6.1 Go version: 1.18.2 darwin/amd64 Gio version in go.mod: gioui.org v0.0.0-20221122135904-dee53b364560
#Example
package main import ( "fmt" "image/color" "log" "os" "gioui.org/app" "gioui.org/font/gofont" "gioui.org/io/event" "gioui.org/io/pointer" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op" "gioui.org/text" "gioui.org/widget/material" ) func main() { w := app.NewWindow() go func() { th := material.NewTheme(gofont.Collection()) var ops op.Ops l := layout.List{Axis: layout.Vertical} for { var e event.Event e = <-w.Events() switch e := e.(type) { case system.DestroyEvent: os.Exit(0) return case system.FrameEvent: gtx := layout.NewContext(&ops, e) l.Layout(gtx, 100, func(gtx layout.Context, index int) layout.Dimensions { for _, ev := range gtx.Queue.Events(index) { pe, ok := ev.(pointer.Event) if !ok { continue } log.Println("clicked", index, pe.Type, pe.Buttons) } pointer.InputOp{Tag: index, Types: pointer.Release}.Add(gtx.Ops) label := material.Label(th, 30, fmt.Sprintf("item: #%d", index)) if index%2 == 0 { label.Color = color.NRGBA{A: 255, R: 200} label.Font.Weight = text.Bold } return layout.Inset{Top: 10, Left: 10}.Layout(gtx, label.Layout) }) e.Frame(&ops) } } }() app.Main() }While I clicked one item, the logs shows that I clicked more than one item.
I tried to solve it myself, but failed. :)
Thank you for your awesome probject!
Ticket created by ~tangyang on ~eliasnaur/gio
panic: metal: [MTLCommandQueue cmdBuffer] failed
goroutine 1 [running, locked to thread]: gioui.org/gpu/internal/metal.(*Backend).ensureCmdBuffer(0xb694c00) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/internal/metal/metal_darwin.go:959 +0x75 gioui.org/gpu/internal/metal.(*Backend).startBlit(0xb694c00) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/internal/metal/metal_darwin.go:499 +0x46 gioui.org/gpu/internal/metal.(*Texture).Upload(0xc00009b830, {0xc00000e2b8?, 0x0?}, {0x1000000045bbc88?, 0x2?}, {0xc000da0000, 0x1?, 0x7e9000}, 0x1e00) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/internal/metal/metal_darwin.go:909 +0x27d gioui.org/gpu/internal/driver.UploadImage({0x45bc968?, 0xc00009b830?}, {0x780?, 0x438?}, 0xc00000e2b8?) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/internal/driver/driver.go:237 +0x6a gioui.org/gpu.(*renderer).texHandle(0xc0001200c0, 0xc0000afc20, {0xc000086280?, {0x4412040?, 0xc000d5a040?}}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/gpu.go:443 +0x213 gioui.org/gpu.(*renderer).uploadImages(...) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/gpu.go:1046 gioui.org/gpu.(*gpu).frame(0xc0000d6d80, {0x45b9440?, 0xc00097a178?}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/gpu.go:392 +0x767 gioui.org/gpu.(*gpu).Frame(0xc00096e0f0?, 0xc0004a95c0?, {0x45b9440, 0xc00097a178}, {0xae6ce40?, 0xc0004a95e0?}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/gpu/gpu.go:359 +0x48 gioui.org/app.(*Window).frame(0xc0000c0000, 0xc0004a96a8?, {0x43c352a?, 0xc0004a9668?}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/window.go:303 +0xa3 gioui.org/app.(*Window).validateAndProcess(0xc0000c0000, {0x45bd7c8, 0xc0000da000}, {0x9?, 0x0?}, 0xd8?, 0x0?, 0x0) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/window.go:264 +0x318 gioui.org/app.(*Window).processEvent(0xc0000c0000, {0x45bd7c8, 0xc0000da000}, {0x45b93c0?, 0xc000089a40?}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/window.go:894 +0xe33 gioui.org/app.(*callbacks).Event(0xc0000c04d8, {0x45b93c0?, 0xc000089a40?}) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/window.go:487 +0x137 gioui.org/app.(*window).draw(0xc0000da000) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/os_macos.go:764 +0x2c5 gioui.org/app.gio_onDraw(0xc0000021a0?) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/os_macos.go:557 +0x37 gioui.org/app._Cfunc_gio_main() _cgo_gotypes.go:398 +0x45 gioui.org/app.osMain(...) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/os_macos.go:899 gioui.org/app.Main(...) /Users/xxx/gopkg/pkg/mod/gioui.org@v0.0.0-20221122135904-dee53b364560/app/app.go:45
Comment by ~tangyang on ~eliasnaur/gio
Thank you!
Ticket created by ~tangyang on ~eliasnaur/gio
package main import ( "image" "image/color" "gioui.org/app" "gioui.org/f32" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op" "gioui.org/op/clip" "gioui.org/op/paint" ) func main() { go func() { var ops op.Ops w := app.NewWindow(app.Size(400, 400)) for e := range w.Events() { switch e := e.(type) { case system.DestroyEvent: return case system.FrameEvent: gtx := layout.NewContext(&ops, e) triangles(gtx) e.Frame(gtx.Ops) } } }() app.Main() } func triangles(ctx layout.Context) layout.Dimensions { size := ctx.Dp(300.0) b := clip.Rect{Max: image.Pt(size, size)} x := b.Push(ctx.Ops) paint.ColorOp{ Color: color.NRGBA{0, 0, 255, 255}, }.Add(ctx.Ops) paint.PaintOp{}.Add(ctx.Ops) x.Pop() p := clip.Path{} p.Begin(ctx.Ops) p.MoveTo(f32.Pt(0, 0)) p.LineTo(f32.Pt(float32(size), 0)) p.LineTo(f32.Pt(0, float32(size))) p.Close() s := clip.Outline{ Path: p.End(), }.Op().Push(ctx.Ops) paint.ColorOp{ Color: color.NRGBA{255, 0, 0, 255}, }.Add(ctx.Ops) paint.PaintOp{}.Add(ctx.Ops) s.Pop() p = clip.Path{} p.Begin(ctx.Ops) p.MoveTo(f32.Pt(float32(size), 0)) p.LineTo(f32.Pt(float32(size), float32(size))) p.LineTo(f32.Pt(0, float32(size))) p.Close() s = clip.Outline{ Path: p.End(), }.Op().Push(ctx.Ops) paint.ColorOp{ Color: color.NRGBA{144, 0, 0, 255}, }.Add(ctx.Ops) paint.PaintOp{}.Add(ctx.Ops) s.Pop() return layout.Dimensions{ Size: image.Pt(size, size), } }