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

app PostFunc is not called because of screen being nil while calling PostFunc [race condition] #276

Open
Viv1k opened this issue May 18, 2019 · 1 comment

Comments

@Viv1k
Copy link

Viv1k commented May 18, 2019

I created a simple app with a window having three texts. I want to call function PostFunc and set their text to something else. But I think PostFunc does not work because of following race condition.

app := &views.Application{}
     app.SetStyle(tcell.StyleDefault.
         Foreground(tcell.ColorWhite).
         Background(tcell.ColorBlack))
     app.SetRootWidget(window)
     app.Start()
     // time.Sleep(1 * time.Second)
     app.PostFunc(setContent)
     if e := app.Wait(); e != nil {
         fmt.Fprintln(os.Stderr, e.Error())
         os.Exit(1)

app.Starts() starts run function in a go routine and creates a screen if some screen is not set.
During the time when called app.Start() called and new screen is not initialize. PostFunc would return saying screen is nil.
Following is PostFunc code:

// PostFunc posts a function to be executed in the context of the
 // application's event loop.  Functions that need to update displayed
 // state, etc. can do this to avoid holding locks.
 func (app *Application) PostFunc(fn func()) {
     ev := &eventAppFunc{fn: fn}
     ev.SetEventNow()
     if scr := app.screen; scr != nil { // Code returns from here
         go func() { scr.PostEventWait(ev) }()
     }
 }
@Viv1k Viv1k changed the title PostFunc app PostFunc is never called May 18, 2019
@Viv1k Viv1k changed the title app PostFunc is never called app PostFunc is not called because of screen being nil while calling PostFunc [race condition] May 18, 2019
@gdamore
Copy link
Owner

gdamore commented Aug 5, 2019

This is a bug in the views sub package, not in tcell itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants