]> git.sesse.net Git - ccbs/blobdiff - bigscreen/ccbs_bigscreen.cpp
In RotateScreen destructor, do not leak subscreen surfaces.
[ccbs] / bigscreen / ccbs_bigscreen.cpp
index e9a30110c5eb449ed67ca0a067f2d6dac4e4eb68..7165bc393006f1843c406bb28943ec04bdfa8652 100644 (file)
@@ -39,8 +39,6 @@ void init(pqxx::connection &conn)
        }
        screens.erase(screens.begin(), screens.end());
 
-       bool show_only_main_screen = (USE_SPLITSCREEN && screens.size() == 1);
-
 #if !USE_SPLITSCREEN
        RotateScreen *rs = new RotateScreen();
        mainscreen = rs;
@@ -69,6 +67,8 @@ void init(pqxx::connection &conn)
                }
        }
 
+       bool show_only_main_screen = (USE_SPLITSCREEN && screens.size() == 1);
+
        /*
         * Show auxilliary screens except if we have too many already,
         * or if we're in the special split-screen end-tournament mode,
@@ -144,14 +144,20 @@ void main_loop(pqxx::connection &conn)
        }
 
        if (mainscreen && mainscreen->check_invalidated()) {
-               mainscreen->draw(framebuf, SCREEN_WIDTH, SCREEN_HEIGHT);
-               SDL_LockSurface(screen);
-               for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
-                       unsigned char *sptr = framebuf + y * SCREEN_WIDTH * 4;
-                       unsigned char *dptr = (unsigned char *)screen->pixels + y * screen->pitch;
-                       memcpy(dptr, sptr, SCREEN_WIDTH * 4);
+               if (screen->pitch == SCREEN_WIDTH * 4) {
+                       SDL_LockSurface(screen);
+                       mainscreen->draw((unsigned char *)screen->pixels, SCREEN_WIDTH, SCREEN_HEIGHT);
+                       SDL_UnlockSurface(screen);
+               } else {
+                       mainscreen->draw(framebuf, SCREEN_WIDTH, SCREEN_HEIGHT);
+                       SDL_LockSurface(screen);
+                       for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
+                               unsigned char *sptr = framebuf + y * SCREEN_WIDTH * 4;
+                               unsigned char *dptr = (unsigned char *)screen->pixels + y * screen->pitch;
+                               memcpy(dptr, sptr, SCREEN_WIDTH * 4);
+                       }
+                       SDL_UnlockSurface(screen);
                }
-               SDL_UnlockSurface(screen);
                SDL_Flip(screen);
                conn.await_notification(0, 10000);
        } else {