@@ -827,7 +827,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
827
827
SDL_Surface * newownedsurf = NULL ;
828
828
int depth = 0 ;
829
829
int flags = 0 ;
830
- int w , h ;
830
+ int w , h , w_actual , h_actual ;
831
831
PyObject * size = NULL ;
832
832
int vsync = SDL_FALSE ;
833
833
intptr_t hwnd = 0 ;
@@ -874,6 +874,9 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
874
874
h = 0 ;
875
875
}
876
876
877
+ h_actual = h ;
878
+ w_actual = w ;
879
+
877
880
if (!SDL_WasInit (SDL_INIT_VIDEO )) {
878
881
/* note SDL works special like this too */
879
882
if (!pg_display_init (NULL , NULL ))
@@ -1096,6 +1099,8 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1096
1099
}
1097
1100
else {
1098
1101
win = SDL_CreateWindow (title , x , y , w_1 , h_1 , sdl_flags );
1102
+ w_actual = w_1 ;
1103
+ h_actual = h_1 ;
1099
1104
}
1100
1105
if (!win )
1101
1106
return RAISE (pgExc_SDLError , SDL_GetError ());
@@ -1316,7 +1321,6 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1316
1321
1317
1322
/* ensure window is always black after a set_mode call */
1318
1323
SDL_FillRect (surf , NULL , SDL_MapRGB (surf -> format , 0 , 0 , 0 ));
1319
- pg_flip_internal (state );
1320
1324
}
1321
1325
1322
1326
/*set the window icon*/
@@ -1340,8 +1344,38 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
1340
1344
}
1341
1345
}
1342
1346
1343
- /*probably won't do much, but can't hurt, and might help*/
1347
+ /*
1348
+ * Can potentially yield a window resize event that forcibly changes
1349
+ * the window size. This would invalidate the current surface we store,
1350
+ * which can cause us to segfault in the event that we reference that
1351
+ * surface later. So we need to flip, which forces us to update that
1352
+ * surface as needed.
1353
+ */
1344
1354
SDL_PumpEvents ();
1355
+ pg_flip_internal (state );
1356
+
1357
+ /*
1358
+ * Tell user if their requested screen size is ignored
1359
+ * OpenGL, SCALED, and FULLSCREEN mess with the screensize in
1360
+ * such a way that it can, at least our internal stuff, can
1361
+ * be respected enough that we don't need to issue a warning
1362
+ */
1363
+ if (!state -> using_gl && ((flags & (PGS_SCALED | PGS_FULLSCREEN )) == 0 ) &&
1364
+ !vsync ) {
1365
+ if (((surface -> surf -> w != w_actual ) ||
1366
+ (surface -> surf -> h != h_actual )) &&
1367
+ ((surface -> surf -> flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) != 0 )) {
1368
+ char buffer [150 ];
1369
+ char * format_string =
1370
+ "Requested window size was smaller than minimum supported "
1371
+ "window size on platform. Using (%d, %d) instead." ;
1372
+ snprintf (buffer , sizeof (buffer ), format_string , surface -> surf -> w ,
1373
+ surface -> surf -> h );
1374
+ if (PyErr_WarnEx (PyExc_RuntimeWarning , buffer , 1 ) != 0 ) {
1375
+ return NULL ;
1376
+ }
1377
+ }
1378
+ }
1345
1379
1346
1380
/*return the window's surface (screen)*/
1347
1381
Py_INCREF (surface );
0 commit comments