88from ctypes import POINTER , c_ubyte , c_void_p , cast
99
1010from pyboy .plugins .base_plugin import PyBoyWindowPlugin
11- from pyboy .utils import WindowEvent , WindowEventMouse , cython_compiled
11+ from pyboy .utils import WindowEvent , WindowEventMouse , cython_compiled , PyBoyAssertException
1212
1313try :
1414 import sdl2
@@ -162,7 +162,9 @@ def __init__(self, pyboy, mb, pyboy_argv):
162162
163163 if not self .enabled ():
164164 return
165- assert sdl2 .SDL_Init (sdl2 .SDL_INIT_VIDEO | sdl2 .SDL_INIT_GAMECONTROLLER ) >= 0
165+
166+ if sdl2 .SDL_InitSubSystem (sdl2 .SDL_INIT_VIDEO | sdl2 .SDL_INIT_GAMECONTROLLER ) < 0 :
167+ raise PyBoyAssertException ("SDL_InitSubSystem video failed: %s" , sdl2 .SDL_GetError ().decode ())
166168
167169 self ._window = sdl2 .SDL_CreateWindow (
168170 b"PyBoy" ,
@@ -188,7 +190,7 @@ def __init__(self, pyboy, mb, pyboy_argv):
188190
189191 def init_audio (self , mb ):
190192 if mb .sound .emulate :
191- if sdl2 .SDL_Init (sdl2 .SDL_INIT_AUDIO ) >= 0 :
193+ if sdl2 .SDL_InitSubSystem (sdl2 .SDL_INIT_AUDIO ) >= 0 :
192194 # NOTE: We have to keep spec variables alive to avoid segfault
193195 self .spec_want = sdl2 .SDL_AudioSpec (self .mb .sound .sample_rate , sdl2 .AUDIO_S8 , 2 , 128 )
194196 self .spec_have = sdl2 .SDL_AudioSpec (0 , 0 , 0 , 0 )
@@ -217,7 +219,7 @@ def init_audio(self, mb):
217219 logger .warning ("SDL_OpenAudioDevice failed: %s" , sdl2 .SDL_GetError ().decode ())
218220 else :
219221 self .sound_support = False
220- logger .warning ("SDL_Init audio failed: %s" , sdl2 .SDL_GetError ().decode ())
222+ logger .warning ("SDL_InitSubSystem audio failed: %s" , sdl2 .SDL_GetError ().decode ())
221223 else :
222224 self .sound_support = False
223225
@@ -303,4 +305,4 @@ def stop(self):
303305 for _ in range (3 ): # At least 2 to close
304306 get_events ()
305307 time .sleep (0.1 )
306- sdl2 .SDL_Quit ( )
308+ sdl2 .SDL_QuitSubSystem ( sdl2 . SDL_INIT_VIDEO | sdl2 . SDL_INIT_GAMECONTROLLER )
0 commit comments