Browse code

ppu_resize: f49143782abd21bb9b53ba5207ac09ab1e4da8e0 was wrong. keep successfully reallocated layers

Sigrid Solveig Haflínudóttir authored on 25/12/2021 15:06:30
Showing 1 changed files
... ...
@@ -57,17 +57,14 @@ ppu_resize(Ppu *p, Uint16 width, Uint16 height)
57 57
 	Uint8
58 58
 		*bg = realloc(p->bg.pixels, width * height),
59 59
 		*fg = realloc(p->fg.pixels, width * height);
60
-	if(!bg || !fg) {
61
-		free(bg);
62
-		free(fg);
63
-		return;
60
+	if(bg) p->bg.pixels = bg;
61
+	if(fg) p->fg.pixels = fg;
62
+	if(bg && fg) {
63
+		p->width = width;
64
+		p->height = height;
65
+		ppu_clear(p, &p->bg);
66
+		ppu_clear(p, &p->fg);
64 67
 	}
65
-	p->bg.pixels = bg;
66
-	p->fg.pixels = fg;
67
-	p->width = width;
68
-	p->height = height;
69
-	ppu_clear(p, &p->bg);
70
-	ppu_clear(p, &p->fg);
71 68
 }
72 69
 
73 70
 void