File: surface_test-Expect-intended-behaviour-if-SDL2-is-new-eno.patch

package info (click to toggle)
pysdl2 0.9.17%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,600 kB
  • sloc: python: 24,691; makefile: 36; sh: 8
file content (66 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From: Simon McVittie <smcv@debian.org>
Date: Fri, 19 Dec 2025 17:58:01 +0000
Subject: surface_test: Expect intended behaviour if SDL2 is new enough

In older versions of "classic" SDL2, including the 2.32.x series,
intersecting an empty rectangle with another rectangle would have an
empty result (w=0, h=0) with an uninitialized position (x, y arbitrary).
However, SDL upstream considers this to be a bug, and it caused
observable visual issues in some older games when used in conjunction
with sdl12-compat.

This test previously asserted that the clip rectangle would not be equal
to the requested clip rectangle, but that was only true because of
this bug: the uninitialized x and y coordinates were very unlikely to be
equal to the requested rectangle. With the bug fix in sdl2-compat,
the coordinates come out as equal to those that were requested.

If SDL2 is sufficiently new, assert that the comparison result is true
(which is the correct result according to SDL upstream), and if not,
make no assertion (in case the bug fix is backported).

Bug: https://github.com/py-sdl/py-sdl2/issues/289
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://github.com/py-sdl/py-sdl2/pull/290
---
 sdl2/test/surface_test.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sdl2/test/surface_test.py b/sdl2/test/surface_test.py
index e8740e8..f241846 100644
--- a/sdl2/test/surface_test.py
+++ b/sdl2/test/surface_test.py
@@ -467,13 +467,20 @@ class TestSDLSurface(object):
             sdl2.SDL_FreeSurface(sf)
 
     def test_SDL_GetSetClipRect(self):
+        # A bug in intersecting empty rectangles was fixed in SDL2 2.33.x
+        # and in sdl2-compat (which reports its version as >= 2.32.50)
+        if sdl2.dll.version_tuple >= (2, 32, 50):
+            true_if_fixed = True
+        else:
+            true_if_fixed = None
+
         rectlist = ((rect.SDL_Rect(0, 0, 0, 0), SDL_FALSE, True),
-                    (rect.SDL_Rect(2, 2, 0, 0), SDL_FALSE, False),
+                    (rect.SDL_Rect(2, 2, 0, 0), SDL_FALSE, true_if_fixed),
                     (rect.SDL_Rect(2, 2, 5, 1), SDL_TRUE, True),
                     (rect.SDL_Rect(6, 5, 10, 3), SDL_TRUE, False),
                     (rect.SDL_Rect(0, 0, 10, 10), SDL_TRUE, True),
-                    (rect.SDL_Rect(0, 0, -10, 10), SDL_FALSE, False),
-                    (rect.SDL_Rect(0, 0, -10, -10), SDL_FALSE, False),
+                    (rect.SDL_Rect(0, 0, -10, 10), SDL_FALSE, true_if_fixed),
+                    (rect.SDL_Rect(0, 0, -10, -10), SDL_FALSE, true_if_fixed),
                     (rect.SDL_Rect(-10, -10, 10, 10), SDL_FALSE, False),
                     (rect.SDL_Rect(10, -10, 10, 10), SDL_FALSE, False),
                     (rect.SDL_Rect(10, 10, 10, 10), SDL_TRUE, False)
@@ -490,7 +497,8 @@ class TestSDLSurface(object):
             sdl2.SDL_GetClipRect(sf, byref(clip))
             err = "Could not set clip rect %s" % r
             assert retval == clipsetval, "retval: " + err
-            assert (clip == r) == cmpval, "clip: " + err
+            if cmpval is not None:
+                assert (clip == r) == cmpval, "clip: " + err
         sdl2.SDL_FreeSurface(sf)
 
     def test_SDL_GetSetSurfaceAlphaMod(self):