Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover from panic on startup and retry #2

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions bench.txt

This file was deleted.

10 changes: 8 additions & 2 deletions cmd/avi/avi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func main() {

s := snappy.NewReader(f)
updates := head.ProtoStreamUpdates(s)
head.Run(updates)
if err := head.Run(updates); err != nil {
log.Fatal(err)
}
return
}

Expand Down Expand Up @@ -115,7 +117,11 @@ func main() {
if *live {
ls := head.NewLiveStream()
drawer = head.NewProxyStream(drawer, ls)
go head.Run(ls.Updates())
go func() {
if err := head.Run(ls.Updates()); err != nil {
log.Fatal(err)
}
}()
}

sim, err := avi.NewSimulation(
Expand Down
21 changes: 20 additions & 1 deletion head/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ func init() {
flatShader, _ = gfxutil.OpenShader("head/models/flat")
}

func Run(updates <-chan FrameUpdate) {
func Run(updates <-chan FrameUpdate) (err error) {
maxStartupRetries := 5
for maxStartupRetries > 0 {
if err = run(updates); err == nil {
// Technically run only returns if it errors, but this is for completeness
return
}
maxStartupRetries--
}
return
}

func run(updates <-chan FrameUpdate) (err error) {
defer func() {
r := recover()
if r != nil {
err = fmt.Errorf("starup error: %v", r)
}
}()
go func() {
// Create our window.
props := window.NewProps()
Expand All @@ -38,6 +56,7 @@ func Run(updates <-chan FrameUpdate) {
go gfxLoopWindow(w, r, updates)
}()
window.MainLoop()
return
}

func gfxLoopWindow(w window.Window, d gfx.Device, updates <-chan FrameUpdate) {
Expand Down