@@ -1302,13 +1302,14 @@ static PyObject *
13021302flood_fill (PyObject * self , PyObject * arg , PyObject * kwargs )
13031303{
13041304 pgSurfaceObject * surfobj ;
1305- pgSurfaceObject * pat_surfobj ;
1305+ pgSurfaceObject * pat_surfobj = NULL ;
13061306 PyObject * colorobj , * start ;
13071307 SDL_Surface * surf = NULL ;
13081308 int startx , starty ;
13091309 Uint32 color ;
13101310 SDL_Surface * pattern = NULL ;
1311- SDL_bool did_lock = SDL_FALSE ;
1311+ SDL_bool did_lock_surf = SDL_FALSE ;
1312+ SDL_bool did_lock_pat = SDL_FALSE ;
13121313 int flood_fill_result ;
13131314
13141315 int drawn_area [4 ] = {INT_MAX , INT_MAX , INT_MIN ,
@@ -1331,19 +1332,10 @@ flood_fill(PyObject *self, PyObject *arg, PyObject *kwargs)
13311332 }
13321333
13331334 if (pgSurface_Check (colorobj )) {
1334- pat_surfobj = ((pgSurfaceObject * )colorobj );
1335-
1336- pattern = SDL_ConvertSurface (pat_surfobj -> surf , surf -> format , 0 );
1337-
1338- if (pattern == NULL ) {
1339- return RAISE (PyExc_RuntimeError , "error converting pattern surf" );
1340- }
1341-
1342- SDL_SetSurfaceRLE (pattern , SDL_FALSE );
1343-
1344- color = 0 ;
1345- }
1346- else {
1335+ pat_surfobj = (pgSurfaceObject * )colorobj ;
1336+ pattern = pat_surfobj -> surf ; /* No conversion: we will map per-pixel */
1337+ color = 0 ; /* new_color unused for pattern path */
1338+ } else {
13471339 CHECK_LOAD_COLOR (colorobj );
13481340 }
13491341
@@ -1352,20 +1344,35 @@ flood_fill(PyObject *self, PyObject *arg, PyObject *kwargs)
13521344 }
13531345
13541346 if (SDL_MUSTLOCK (surf )) {
1355- did_lock = SDL_TRUE ;
1347+ did_lock_surf = SDL_TRUE ;
13561348 if (!pgSurface_Lock (surfobj )) {
13571349 return RAISE (PyExc_RuntimeError , "error locking surface" );
13581350 }
13591351 }
1352+ if (pattern && SDL_MUSTLOCK (pattern )) {
1353+ did_lock_pat = SDL_TRUE ;
1354+ if (!pgSurface_Lock (pat_surfobj )) {
1355+ if (did_lock_surf ) {
1356+ pgSurface_Unlock (surfobj );
1357+ }
1358+ return RAISE (PyExc_RuntimeError , "error locking pattern surface" );
1359+ }
1360+ }
13601361
13611362 flood_fill_result =
13621363 flood_fill_inner (surf , startx , starty , color , pattern , drawn_area );
13631364
1364- if (pattern != NULL ) {
1365- SDL_FreeSurface (pattern );
1366- }
1365+ /* no allocated pattern surface to free */
13671366
1368- if (did_lock ) {
1367+ if (did_lock_pat ) {
1368+ if (!pgSurface_Unlock (pat_surfobj )) {
1369+ if (did_lock_surf ) {
1370+ pgSurface_Unlock (surfobj );
1371+ }
1372+ return RAISE (PyExc_RuntimeError , "error unlocking pattern surface" );
1373+ }
1374+ }
1375+ if (did_lock_surf ) {
13691376 if (!pgSurface_Unlock (surfobj )) {
13701377 return RAISE (PyExc_RuntimeError , "error unlocking surface" );
13711378 }
@@ -1384,7 +1391,6 @@ flood_fill(PyObject *self, PyObject *arg, PyObject *kwargs)
13841391 else
13851392 return pgRect_New4 (startx , starty , 0 , 0 );
13861393}
1387-
13881394/* Functions used in drawing algorithms */
13891395
13901396static void
0 commit comments