From 25e857228f57c91251a5106585d9bfd7d0873825 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 1 Dec 2024 02:16:48 +0100 Subject: [PATCH] init_mgl_context fails when no callback is provided --- CHANGELOG.md | 5 +++++ docs/conf.py | 2 +- moderngl_window/__init__.py | 2 +- moderngl_window/context/base/window.py | 11 +++++++---- pyproject.toml | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83eaef4..6c31107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.0.2 + +* Fixed an issue causing `BaseWindow.init_mgl_context` to fail if no context + creation callback was provided. + ## 3.0.1 * Timers now have `fps` and `fps_average` properties for obtaining the current and average frame rate diff --git a/docs/conf.py b/docs/conf.py index a748936..771b936 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,7 +60,7 @@ def __getattr__(cls: Any, name: Any) -> MagicMock: author = "Einar Forselv" # The short X.Y version -version = "3.0.1" +version = "3.0.2" # The full version, including alpha/beta/rc tags release = version diff --git a/moderngl_window/__init__.py b/moderngl_window/__init__.py index 9fbad18..565ab45 100644 --- a/moderngl_window/__init__.py +++ b/moderngl_window/__init__.py @@ -19,7 +19,7 @@ from moderngl_window.utils.keymaps import AZERTY, QWERTY, KeyMap, KeyMapFactory # noqa from moderngl_window.utils.module_loading import import_string -__version__ = "3.0.1" +__version__ = "3.0.2" IGNORE_DIRS = [ "__pycache__", diff --git a/moderngl_window/context/base/window.py b/moderngl_window/context/base/window.py index e8fc706..cdfb569 100644 --- a/moderngl_window/context/base/window.py +++ b/moderngl_window/context/base/window.py @@ -92,7 +92,7 @@ def __init__( samples: int = 0, cursor: bool = True, backend: Optional[str] = None, - context_creation_func: Optional[Callable] = None, + context_creation_func: Optional[Callable[[], Optional[moderngl.Context]]] = None, **kwargs: Any, ) -> None: """Initialize a window instance. @@ -190,10 +190,13 @@ def init_mgl_context(self) -> None: Keyword Args: ctx: An optional custom ModernGL context """ + ctx: Optional[moderngl.Context] = None if self._context_creation_func: - self._ctx = self._context_creation_func() - if self._ctx is None: - self._ctx = moderngl.create_context(require=self.gl_version_code) + ctx = self._context_creation_func() + if ctx is None: + ctx = moderngl.create_context(require=self.gl_version_code) + self._ctx = ctx + err = self._ctx.error if err != "GL_NO_ERROR": logger.info("Consumed the following error during context creation: %s", err) diff --git a/pyproject.toml b/pyproject.toml index 2185960..7a31922 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "moderngl-window" -version = "3.0.1" +version = "3.0.2" description = "A cross platform helper library for ModernGL making window creation and resource loading simple" readme = "README.md" authors = [{ name = "Einar Forselv", email = "eforselv@gmail.com" }]