Index: apps/plugins/brickmania.c
===================================================================
--- apps/plugins/brickmania.c	(revisione 27856)
+++ apps/plugins/brickmania.c	(copia locale)
@@ -1520,6 +1520,20 @@
     }
 }
 
+static void newround()
+{
+    brickmania_init_game(false);
+    brickmania_sleep(2);
+}
+
+static void error_newround(const char * message)
+{
+    rb->splash(HZ*3,"Some error happened, so the current balls will be killed.");
+    rb->splashf(HZ*3,"The reason is: %s",message);
+    rb->splash(HZ*3,"Don't worry, it's my fault, you won't lose any life for this. :)");
+    newround(); 
+}
+
 static int brickmania_game_loop(void)
 {
     int j,i,k;
@@ -1605,10 +1619,17 @@
 
             /* draw the ball */
             for(i=0;i<used_balls;i++)
+            {
+                /* MI: workaround for balls exiting from the screen */
+                const int H_OFFSCREEN_LIMIT=GAMESCREEN_WIDTH*3/2;
+                const int V_OFFSCREEN_LIMIT=GAMESCREEN_HEIGHT*3/2;
+                if(abs(ball[i].pos_x)>H_OFFSCREEN_LIMIT || abs(ball[i].pos_y)>V_OFFSCREEN_LIMIT)
+                    error_newround("Ball went offscreen");
                 rb->lcd_bitmap(brickmania_ball,
                     INT3(ball[i].pos_x - HALFBALL),
                     INT3(ball[i].pos_y - HALFBALL),
                     INT3(BALL), INT3(BALL));
+            }
 
             if (brick_on_board==0)
                 brick_on_board--;
