Skip to content

Commit d529e61

Browse files
committed
Use raise_sdl_err for more error checking
1 parent 0700f2e commit d529e61

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

sdl2/ext/draw.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ctypes
22
from .compat import isiterable, UnsupportedError
3+
from .common import raise_sdl_err
34
from .array import to_ctypes
45
from .color import convert_to_color
56
from .. import surface, pixels, rect
@@ -93,11 +94,13 @@ def fill(target, color, area=None):
9394
if len(rects) > 2:
9495
rects, count = to_ctypes(rects, rect.SDL_Rect)
9596
rects = ctypes.cast(rects, ctypes.POINTER(rect.SDL_Rect))
96-
surface.SDL_FillRects(rtarget, rects, count, color)
97+
ret = surface.SDL_FillRects(rtarget, rects, count, color)
9798
elif len(rects) == 1:
98-
surface.SDL_FillRect(rtarget, rects[0], color)
99+
ret = surface.SDL_FillRect(rtarget, rects[0], color)
99100
else:
100-
surface.SDL_FillRect(rtarget, None, color)
101+
ret = surface.SDL_FillRect(rtarget, None, color)
102+
if ret < 0:
103+
raise_sdl_err("filling the surface")
101104

102105

103106
def line(target, color, dline, width=1):

sdl2/ext/msgbox.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from ctypes import byref, c_int
22
from .color import Color
33
from .compat import isiterable, utf8
4-
from .common import SDLError
4+
from .common import raise_sdl_err
55
from .window import Window
6-
from .. import dll, error, SDL_PumpEvents, SDL_Window
6+
from .. import dll, SDL_PumpEvents, SDL_Window
77
from .. import messagebox as mb
88

99
__all__ = [
@@ -191,13 +191,7 @@ def show_messagebox(msgbox, window=None):
191191
if ret == 0:
192192
return msgbox._buttons[resp.value]
193193
else:
194-
# NOTE: replace with raise_sdl_err now that it exists?
195-
errmsg = error.SDL_GetError().decode('utf-8')
196-
error.SDL_ClearError()
197-
e = "Error encountered displaying message box"
198-
if len(errmsg):
199-
e += ": {0}".format(errmsg)
200-
raise SDLError(e)
194+
raise_sdl_err("displaying the message box")
201195

202196

203197
def show_alert(title, msg, msgtype=None, window=None):
@@ -229,11 +223,5 @@ def show_alert(title, msg, msgtype=None, window=None):
229223
window
230224
)
231225
SDL_PumpEvents()
232-
if ret != 0:
233-
# NOTE: replace with raise_sdl_err now that it exists?
234-
errmsg = error.SDL_GetError().decode('utf-8')
235-
error.SDL_ClearError()
236-
e = "Error encountered displaying message box"
237-
if len(errmsg):
238-
e += ": {0}".format(errmsg)
239-
raise SDLError(e)
226+
if ret < 0:
227+
raise_sdl_err("displaying the message box")

0 commit comments

Comments
 (0)