From 0cd832f096372dc83d06abe82b0493e353127716 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 30 Mar 2023 01:45:22 +0900 Subject: [PATCH] internal/graphicsdriver/directx: check the DLL availability at NewGraphics Updates #2613 Updates #2618 --- internal/graphicsdriver/directx/d3d_windows.go | 6 +++++- internal/graphicsdriver/directx/graphics_windows.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/graphicsdriver/directx/d3d_windows.go b/internal/graphicsdriver/directx/d3d_windows.go index ef413df6d..ccc34aa32 100644 --- a/internal/graphicsdriver/directx/d3d_windows.go +++ b/internal/graphicsdriver/directx/d3d_windows.go @@ -95,8 +95,12 @@ func init() { procD3DCompile = d3dcompiler.NewProc("D3DCompile") } +func isD3DCompilerDLLAvailable() bool { + return procD3DCompile != nil +} + func _D3DCompile(srcData []byte, sourceName string, pDefines []_D3D_SHADER_MACRO, pInclude unsafe.Pointer, entryPoint string, target string, flags1 uint32, flags2 uint32) (*_ID3DBlob, error) { - if procD3DCompile == nil { + if !isD3DCompilerDLLAvailable() { return nil, fmt.Errorf("directx: d3dcompiler_*.dll is missing in this environment") } diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index 99a26600f..831de4977 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -73,6 +73,10 @@ func parseFeatureLevel(str string) (_D3D_FEATURE_LEVEL, bool) { // NewGraphics creates an implementation of graphicsdriver.Graphics for DirectX. // The returned graphics value is nil iff the error is not nil. func NewGraphics() (graphicsdriver.Graphics, error) { + if !isD3DCompilerDLLAvailable() { + return nil, fmt.Errorf("directx: d3dcompiler_*.dll is missing in this environment") + } + var useWARP bool var useDebugLayer bool version := 11