Skip to content

Commit

Permalink
init_mgl_context fails when no callback is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Dec 1, 2024
1 parent 5944113 commit 25e8572
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion moderngl_window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
11 changes: 7 additions & 4 deletions moderngl_window/context/base/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }]
Expand Down

0 comments on commit 25e8572

Please sign in to comment.