Skip to content

Commit fb10ffe

Browse files
committed
Fix CI regressions
SDL_CommonEvent and others needed to be marked as packed/flexible Closing audio streams atexit seems to cause race conditions Remove outdated Sphinx directives Check if audio devices work before testing them
1 parent 39d28d4 commit fb10ffe

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

build_sdl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"SDL_TouchFingerEvent",
5252
"SDL_MultiGestureEvent",
5353
"SDL_DollarGestureEvent",
54+
"SDL_CommonEvent",
55+
"SDL_DisplayEvent",
5456
)
5557

5658
# Other defined names which sometimes cause issues when parsed.

docs/sdl/joystick.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@ SDL Joystick Support ``tcod.sdl.joystick``
33

44
.. automodule:: tcod.sdl.joystick
55
:members:
6-
:exclude-members:
7-
Power
8-
9-
.. autoclass:: tcod.sdl.joystick.Power
10-
:members:
11-
:member-order: bysource

tcod/sdl/audio.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
from __future__ import annotations
3939

40-
import atexit
4140
import contextlib
4241
import enum
4342
import sys
@@ -483,14 +482,6 @@ class AudioStreamCallbackData:
483482
_audio_stream_registry: weakref.WeakValueDictionary[int, AudioStream] = weakref.WeakValueDictionary()
484483

485484

486-
@atexit.register
487-
def _unlink_audio_callbacks() -> None:
488-
"""Deletes AudioStream callbacks to ensure a graceful application exit."""
489-
for stream in _audio_stream_registry.values():
490-
stream.getter_callback = None
491-
stream.putter_callback = None
492-
493-
494485
class AudioStream:
495486
"""An SDL audio stream.
496487
@@ -674,11 +665,13 @@ def getter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
674665
@getter_callback.setter
675666
def getter_callback(self, callback: Callable[[AudioStream, AudioStreamCallbackData], Any] | None, /) -> None:
676667
if callback is None:
677-
lib.SDL_SetAudioStreamGetCallback(self._stream_p, ffi.NULL, ffi.NULL)
668+
_check(lib.SDL_SetAudioStreamGetCallback(self._stream_p, ffi.NULL, ffi.NULL))
678669
_audio_stream_get_callbacks.pop(self, None)
679670
else:
680671
_audio_stream_get_callbacks[self] = callback
681-
lib.SDL_SetAudioStreamGetCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
672+
_check(
673+
lib.SDL_SetAudioStreamGetCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
674+
)
682675

683676
@property
684677
def putter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], Any] | None:
@@ -692,11 +685,13 @@ def putter_callback(self) -> Callable[[AudioStream, AudioStreamCallbackData], An
692685
@putter_callback.setter
693686
def putter_callback(self, callback: Callable[[AudioStream, AudioStreamCallbackData], Any] | None, /) -> None:
694687
if callback is None:
695-
lib.SDL_SetAudioStreamPutCallback(self._stream_p, ffi.NULL, ffi.NULL)
688+
_check(lib.SDL_SetAudioStreamPutCallback(self._stream_p, ffi.NULL, ffi.NULL))
696689
_audio_stream_put_callbacks.pop(self, None)
697690
else:
698691
_audio_stream_put_callbacks[self] = callback
699-
lib.SDL_SetAudioStreamPutCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 0))
692+
_check(
693+
lib.SDL_SetAudioStreamPutCallback(self._stream_p, lib._sdl_audio_stream_callback, ffi.cast("void*", 1))
694+
)
700695

701696

702697
class _LoopSoundFunc:
@@ -806,7 +801,8 @@ def stop(self) -> None:
806801
class BasicMixer:
807802
"""An SDL sound mixer implemented in Python and Numpy.
808803
809-
Example:
804+
Example::
805+
810806
import time
811807
812808
import soundfile # pip install soundfile
@@ -1032,17 +1028,10 @@ def open( # noqa: A001, PLR0913
10321028
paused:
10331029
If True then the device will begin in a paused state.
10341030
It can then be unpaused by assigning False to :any:`AudioDevice.paused`.
1035-
callback:
1036-
If None then this device will be opened in push mode and you'll have to use :any:`AudioDevice.queue_audio`
1037-
to send audio data or :any:`AudioDevice.dequeue_audio` to receive it.
1038-
If a callback is given then you can change it later, but you can not enable or disable the callback on an
1039-
opened device.
1040-
If True then a default callback which plays silence will be used, this is useful if you need the audio
1041-
device before your callback is ready.
1031+
callback: An optional callback to use, this is deprecated.
10421032
10431033
If a callback is given then it will be called with the `AudioDevice` and a Numpy buffer of the data stream.
10441034
This callback will be run on a separate thread.
1045-
Exceptions not handled by the callback become unraiseable and will be handled by :any:`sys.unraisablehook`.
10461035
10471036
.. versionchanged:: Unreleased
10481037
SDL3 returns audio devices differently, exact formatting is set with :any:`AudioDevice.new_stream` instead.

tests/test_sdl_audio.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import sys
55
import time
6+
from collections.abc import Callable
67
from typing import Any
78

89
import numpy as np
@@ -14,11 +15,19 @@
1415
# ruff: noqa: D103
1516

1617

18+
def device_works(device: Callable[[], tcod.sdl.audio.AudioDevice]) -> bool:
19+
try:
20+
device().open().close()
21+
except RuntimeError:
22+
return False
23+
return True
24+
25+
1726
needs_audio_device = pytest.mark.xfail(
18-
not list(tcod.sdl.audio.get_devices()), reason="This test requires an audio device"
27+
not device_works(tcod.sdl.audio.get_default_playback), reason="This test requires an audio device"
1928
)
2029
needs_audio_capture = pytest.mark.xfail(
21-
not list(tcod.sdl.audio.get_capture_devices()), reason="This test requires an audio capture device"
30+
not device_works(tcod.sdl.audio.get_default_recording), reason="This test requires an audio capture device"
2231
)
2332

2433

0 commit comments

Comments
 (0)