Skip to content

Commit 0d1e826

Browse files
Merge pull request #2839 from pygame-community/permissive-converting
relax convert conditions
2 parents 8a0744d + 34c1e0c commit 0d1e826

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

docs/reST/ref/surface.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@
247247
as Surface subclass inherit this method without the need to override,
248248
unless subclass specific instance attributes also need copying.
249249

250+
.. versionchanged:: 2.5.0 converting to a known format will succeed without a window/display surface.
251+
250252
.. ## Surface.convert ##
251253
252254
.. method:: convert_alpha

src_c/surface.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,13 +1423,14 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
14231423
Uint8 key_r, key_g, key_b, key_a = 255;
14241424
int has_colorkey = SDL_FALSE;
14251425

1426-
if (!SDL_WasInit(SDL_INIT_VIDEO))
1427-
return RAISE(pgExc_SDLError,
1428-
"cannot convert without pygame.display initialized");
1429-
14301426
if (!PyArg_ParseTuple(args, "|Oi", &argobject, &flags))
14311427
return NULL;
14321428

1429+
if (!argobject && !SDL_WasInit(SDL_INIT_VIDEO))
1430+
return RAISE(pgExc_SDLError,
1431+
"cannot convert without format "
1432+
"when pygame.display is not initialized");
1433+
14331434
SURF_INIT_CHECK(surf)
14341435

14351436
pgSurface_Prep(self);

test/surface_test.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,6 @@ def test_image_convert_bug_131(self):
12151215

12161216
pygame.display.init()
12171217
try:
1218-
pygame.display.set_mode((640, 480))
1219-
12201218
im = pygame.image.load(example_path(os.path.join("data", "city.png")))
12211219
im2 = pygame.image.load(example_path(os.path.join("data", "brick.png")))
12221220

@@ -1246,7 +1244,7 @@ def test_convert_init(self):
12461244
filename = example_path(os.path.join("data", "alien3.png")) # 8bit PNG
12471245
surf8bit = pygame.image.load(filename)
12481246

1249-
self.assertRaisesRegex(pygame.error, "display initialized", surf.convert)
1247+
self.assertRaisesRegex(pygame.error, "display is not initialized", surf.convert)
12501248

12511249
pygame.display.init()
12521250
try:
@@ -1308,8 +1306,6 @@ def test_convert_alpha_SRCALPHA(self):
13081306
def test_convert_palettize(self):
13091307
pygame.display.init()
13101308
try:
1311-
pygame.display.set_mode((640, 480))
1312-
13131309
surf = pygame.Surface((150, 250))
13141310
surf.fill((255, 50, 0))
13151311
surf = surf.convert(8)

0 commit comments

Comments
 (0)