DEADSOFTWARE

software: fix crashes on buffer resize
[flatwaifu.git] / src / soft / vga.c
index d9c77e1e8dea01a24339a990bd5f0da209f503bc..a747a31495e8547818539bcfca7cb35d46d3c23f 100644 (file)
@@ -64,6 +64,11 @@ vgaimg *V_loadvgaimg (char *name) {
   return V_getvgaimg(F_getresid(name));
 }
 
+void V_update_buffer (void) {
+  Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch);
+  V_setrect(0, 0, buf_w, buf_h);
+}
+
 static void draw_rect (int x, int y, int w, int h, int c) {
   int i;
   int x0 = max(x, cx1);
@@ -77,10 +82,12 @@ static void draw_rect (int x, int y, int w, int h, int c) {
 }
 
 void V_setrect (short x, short w, short y, short h) {
+  assert(w >= 0);
+  assert(h >= 0);
   cx1 = max(x, 0);
-  cx2 = min(x + w - 1, SCRW - 1);
+  cx2 = min(x + w - 1, buf_w - 1);
   cy1 = max(y, 0);
-  cy2 = min(y + h - 1, SCRH - 1);
+  cy2 = min(y + h - 1, buf_h - 1);
 }
 
 static void putpixel (int x, int y, byte color) {
@@ -100,7 +107,7 @@ static void mappixel (int x, int y, byte *cmap) {
 
 void V_center (int f) {
   if (f) {
-    V_offset(SCRW / 2 - 320 / 2, SCRH / 2 - 200 / 2);
+    V_offset(buf_w / 2 - 320 / 2, buf_h / 2 - 200 / 2);
   } else {
     V_offset(0, 0);
   }