8
8
from ctypes import POINTER , c_ubyte , c_void_p , cast
9
9
10
10
from 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
12
12
13
13
try :
14
14
import sdl2
@@ -162,7 +162,9 @@ def __init__(self, pyboy, mb, pyboy_argv):
162
162
163
163
if not self .enabled ():
164
164
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 ())
166
168
167
169
self ._window = sdl2 .SDL_CreateWindow (
168
170
b"PyBoy" ,
@@ -188,7 +190,7 @@ def __init__(self, pyboy, mb, pyboy_argv):
188
190
189
191
def init_audio (self , mb ):
190
192
if mb .sound .emulate :
191
- if sdl2 .SDL_Init (sdl2 .SDL_INIT_AUDIO ) >= 0 :
193
+ if sdl2 .SDL_InitSubSystem (sdl2 .SDL_INIT_AUDIO ) >= 0 :
192
194
# NOTE: We have to keep spec variables alive to avoid segfault
193
195
self .spec_want = sdl2 .SDL_AudioSpec (self .mb .sound .sample_rate , sdl2 .AUDIO_S8 , 2 , 128 )
194
196
self .spec_have = sdl2 .SDL_AudioSpec (0 , 0 , 0 , 0 )
@@ -217,7 +219,7 @@ def init_audio(self, mb):
217
219
logger .warning ("SDL_OpenAudioDevice failed: %s" , sdl2 .SDL_GetError ().decode ())
218
220
else :
219
221
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 ())
221
223
else :
222
224
self .sound_support = False
223
225
@@ -303,4 +305,4 @@ def stop(self):
303
305
for _ in range (3 ): # At least 2 to close
304
306
get_events ()
305
307
time .sleep (0.1 )
306
- sdl2 .SDL_Quit ( )
308
+ sdl2 .SDL_QuitSubSystem ( sdl2 . SDL_INIT_VIDEO | sdl2 . SDL_INIT_GAMECONTROLLER )
0 commit comments