fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.29k stars 1.41k forks source link

Better error handling for OpenGL errors #4145

Open xxandev opened 1 year ago

xxandev commented 1 year ago

Checklist

Is your feature request related to a problem?

APIUnavailable: WGL: The driver does not appear to support OpenGL image

Hello, please advise on how to handle errors without modifying the library? The methods func (fyne.Window).ShowAndRun(), func (fyne.App).Run(), func (fyne.Driver).Run() do not return errors; they handle them internally within the methods. In case the user interface fails to launch, it is necessary to perform a series of actions before terminating the program.

Is it possible to construct a solution with the existing API?

No response

Describe the solution you'd like to see.

In my opinion, it would be very convenient to have the ability to handle errors.

func (fyne.Window).ShowAndRun() error
func (fyne.App).Run() error
func (fyne.Driver).Run() error
FyneApp := app.New()

// .....

if err := FyneApp.Run(); err != nil {
    // event 1
    // event 2
    // ...
    // event N
    panic(err)
}
xxandev commented 1 year ago

https://github.com/fyne-io/fyne/issues/4033#issuecomment-1652726057

I'm aware of this solution, but I would like to have the ability to handle errors.

Jacalz commented 1 year ago

Adding errors to the mentioned APIs would be a breaking change and I’m also not sure how useful it would be. Errors there occur very rarely and if you get one of the failures there, there is not much you can do from the binary to correct it. The user basically has to install the right drivers (if they exist) or enable 3D acceleration if running in a virtual machine.

Jacalz commented 1 year ago

You might be able to use recover() to catch the panic but I can’t guarantee anything.

xxandev commented 1 year ago

I don't mean recovering the user interface functionality. I want to perform a series of actions in case such an issue arises:

I was considering using recover(), but it doesn't seem to be the optimal approach, and I'm not sure it will work, as recover() needs to be called with defer in the function that invokes panic.

xxandev commented 1 year ago

Perhaps, in order to avoid altering the current API since the changes are indeed critical, you could add a variable to the class that contains a function OnFatal or OnPanic, and invoke it in similar situations. This way, the API remains unchanged and users have the option to handle such issues independently.

yuolr commented 1 year ago

You can download a opengl.dll newer, and put it in your application installation directory