From d101e3390b595643145e6aa1c7804e865e73cd15 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Mon, 9 Dec 2024 14:36:56 +0100 Subject: [PATCH] Allow get_context before a backend is selected --- wgpu/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wgpu/__init__.py b/wgpu/__init__.py index 3fad8cce..68c166a3 100644 --- a/wgpu/__init__.py +++ b/wgpu/__init__.py @@ -24,7 +24,9 @@ def rendercanvas_context_hook(canvas, present_methods): backend_module = gpu.__module__ if backend_module in ("", "wgpu._classes"): - raise RuntimeError( - "A backend must be selected (e.g. with wgpu.gpu.request_adapter()) before canvas.get_context() can be called." - ) + # Load backend now + from .backends import auto + + backend_module = gpu.__module__ + return sys.modules[backend_module].GPUCanvasContext(canvas, present_methods)