charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
27.24k stars 788 forks source link

SetWindowTitle panic after upgrade from v0.26.2 -> v0.26.3 #1029

Closed DziedzicGrzegorz closed 4 months ago

DziedzicGrzegorz commented 4 months ago

Describe the bug

The application crashes with a runtime error: "invalid memory address or nil pointer dereference" when trying to set the window title using Bubble Tea's SetWindowTitle method.

This behavior occurs on both Windows and Ubuntu

Source Code

func main() {
    var rootCmd = &cobra.Command{
        Use:   "game",
        Short: "Tic-Tac-Toe game",
        Long:  "A simple Tic-Tac-Toe game written in Go using the Bubble Tea library and the Lip Gloss library.",
        Run: func(cmd *cobra.Command, args []string) {
            p := tea.NewProgram(model{}, tea.WithAltScreen())
            p.SetWindowTitle("Welcome to the game")
            if _, err := p.Run(); err != nil {
                fmt.Fprintf(os.Stderr, "Error: %v\n", err)
                os.Exit(1)
            }
        },
    }

    if err := rootCmd.Execute(); err != nil {
        fmt.Fprintf(os.Stderr, "Error: %v\n", err)
        os.Exit(1)
    }
}

nilPointer

aymanbagabas commented 4 months ago

Hi @DziedzicGrzegorz, that's a bug indeed! FWIW, using p.SetWindowTitle is deprecated or should be, you should use tea.SetWindowTitle instead in your model Init(). Meanwhile, I will push a fix for this bug momentarily.