internal/ui: bug fix: the env variable should be used only when the library is not specified

Updates #2378
This commit is contained in:
Hajime Hoshi 2022-12-29 15:44:18 +09:00
parent 8d020ad414
commit e5b9569142
2 changed files with 21 additions and 20 deletions

2
doc.go
View File

@ -67,7 +67,7 @@
//
// `EBITENGINE_GRAPHICS_LIBRARY` environment variable specifies the graphics library.
// If the specified graphics library is not available, RunGame returns an error.
// This environment variable can also be set programmatically through os.Setenv before RunGame is called.
// This environment variable works when RunGame is called or RunGameWithOptions is called with GraphicsLibraryAuto.
// This can take one of the following value:
//
// "auto": Ebitengine chooses the graphics library automatically. This is the default value.

View File

@ -29,6 +29,7 @@ type graphicsDriverCreator interface {
}
func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLibrary) (graphicsdriver.Graphics, error) {
if graphicsLibrary == GraphicsLibraryAuto {
envName := "EBITENGINE_GRAPHICS_LIBRARY"
env := os.Getenv(envName)
if env == "" {
@ -39,8 +40,7 @@ func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLi
switch env {
case "", "auto":
// Use the specified graphics library.
// Otherwise, prefer the environment variable.
// Keep the automatic choosing.
case "opengl":
graphicsLibrary = GraphicsLibraryOpenGL
case "directx":
@ -50,6 +50,7 @@ func newGraphicsDriver(creator graphicsDriverCreator, graphicsLibrary GraphicsLi
default:
return nil, fmt.Errorf("ui: an unsupported graphics library is specified by the environment variable: %s", env)
}
}
switch graphicsLibrary {
case GraphicsLibraryAuto: