diff --git a/src/r_picformats.c b/src/r_picformats.c
index 8117d08d5c10173ffc320a3953b7d0f260f671c3..7d7f1198d1805b24b715f78a339b07c952dd4e04 100644
--- a/src/r_picformats.c
+++ b/src/r_picformats.c
@@ -958,7 +958,6 @@ static int PNG_ChunkReader(png_structp png_ptr, png_unknown_chunkp chonk)
 static void PNG_error(png_structp PNG, png_const_charp pngtext)
 {
 	CONS_Debug(DBG_RENDER, "libpng error at %p: %s", PNG, pngtext);
-	//I_Error("libpng error at %p: %s", PNG, pngtext);
 }
 
 static void PNG_warn(png_structp PNG, png_const_charp pngtext)
@@ -1025,7 +1024,7 @@ static png_bytep *PNG_Read(
 	png_set_read_fn(png_ptr, &png_io, PNG_IOReader);
 
 	memset(&chunk, 0x00, sizeof(png_chunk_t));
-	chunkname = grAb_chunk; // I want to read a grAb chunk
+	chunkname = grAb_chunk;
 
 	user_chunk_ptr = png_get_user_chunk_ptr(png_ptr);
 	png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, PNG_ChunkReader);
@@ -1410,13 +1409,17 @@ boolean Picture_PNGDimensions(UINT8 *png, INT32 *width, INT32 *height, INT16 *to
 
 	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, PNG_error, PNG_warn);
 	if (!png_ptr)
-		I_Error("Picture_PNGDimensions: Couldn't initialize libpng!");
+	{
+		CONS_Alert(CONS_ERROR, "Picture_PNGDimensions: Couldn't initialize libpng!\n");
+		return false;
+	}
 
 	png_info_ptr = png_create_info_struct(png_ptr);
 	if (!png_info_ptr)
 	{
 		png_destroy_read_struct(&png_ptr, NULL, NULL);
-		I_Error("Picture_PNGDimensions: libpng couldn't allocate memory!");
+		CONS_Alert(CONS_ERROR, "Picture_PNGDimensions: libpng couldn't allocate memory!\n");
+		return false;
 	}
 
 #ifdef USE_FAR_KEYWORD
@@ -1426,7 +1429,8 @@ boolean Picture_PNGDimensions(UINT8 *png, INT32 *width, INT32 *height, INT16 *to
 #endif
 	{
 		png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL);
-		I_Error("Picture_PNGDimensions: libpng load error!");
+		CONS_Alert(CONS_ERROR, "Picture_PNGDimensions: libpng load error!\n");
+		return false;
 	}
 #ifdef USE_FAR_KEYWORD
 	png_memcpy(png_jmpbuf(png_ptr), jmpbuf, sizeof jmp_buf);
@@ -1438,7 +1442,7 @@ boolean Picture_PNGDimensions(UINT8 *png, INT32 *width, INT32 *height, INT16 *to
 	png_set_read_fn(png_ptr, &png_io, PNG_IOReader);
 
 	memset(&chunk, 0x00, sizeof(png_chunk_t));
-	chunkname = grAb_chunk; // I want to read a grAb chunk
+	chunkname = grAb_chunk;
 
 	user_chunk_ptr = png_get_user_chunk_ptr(png_ptr);
 	png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr, PNG_ChunkReader);
diff --git a/src/r_segs.c b/src/r_segs.c
index d8267ea6fbb03c605b230ce83bb8decf3978c108..ae46a4aeb5bc62ebceaf04e12e3ab986d8f15490 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -176,13 +176,12 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
 	R_CheckTextureCache(texnum);
 
 	if (textures[texnum]->flip & 2) // vertically flipped?
-	{
 		colfunc_2s = R_DrawFlippedMaskedColumn;
-		lengthcol = textures[texnum]->height;
-	}
 	else
 		colfunc_2s = R_DrawMaskedColumn; // render the usual 2sided single-patch packed texture
 
+	lengthcol = textures[texnum]->height;
+
 	// Setup lighting based on the presence/lack-of 3D floors.
 	dc_numlights = 0;
 	if (frontsector->numlights)
@@ -740,13 +739,12 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
 	R_CheckTextureCache(texnum);
 
 	if (textures[texnum]->flip & 2) // vertically flipped?
-	{
 		colfunc_2s = R_DrawRepeatFlippedMaskedColumn;
-		lengthcol = textures[texnum]->height;
-	}
 	else
 		colfunc_2s = R_DrawRepeatMaskedColumn; // render the usual 2sided single-patch packed texture
 
+	lengthcol = textures[texnum]->height;
+
 	// Set heights according to plane, or slope, whichever
 	{
 		fixed_t right_top, right_bottom;
diff --git a/src/r_textures.c b/src/r_textures.c
index 2d38133a33aa5b7b1fd50f83d51badfcac668ba5..de62c1511db483627ab26559a3019b75bdfe74f7 100644
--- a/src/r_textures.c
+++ b/src/r_textures.c
@@ -816,9 +816,16 @@ Rloadflats (INT32 i, INT32 w)
 		{
 			INT32 texw, texh;
 			UINT8 *flatlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
-			Picture_PNGDimensions((UINT8 *)flatlump, &texw, &texh, NULL, NULL, lumplength);
-			width = (INT16)width;
-			height = (INT16)height;
+			if (Picture_PNGDimensions((UINT8 *)flatlump, &texw, &texh, NULL, NULL, lumplength))
+			{
+				width = (INT16)width;
+				height = (INT16)height;
+			}
+			else
+			{
+				width = 1;
+				height = 1;
+			}
 			Z_Free(flatlump);
 		}
 #endif
@@ -891,16 +898,23 @@ Rloadtextures (INT32 i, INT32 w)
 		lumplength = W_LumpLengthPwad(wadnum, lumpnum);
 #endif
 
-		INT16 width, height;
+		INT16 width = 0, height = 0;
 
 #ifndef NO_PNG_LUMPS
 		if (Picture_IsLumpPNG((UINT8 *)&patchlump, lumplength))
 		{
 			INT32 texw, texh;
 			UINT8 *png = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
-			Picture_PNGDimensions(png, &texw, &texh, NULL, NULL, lumplength);
-			width = (INT16)width;
-			height = (INT16)height;
+			if (Picture_PNGDimensions(png, &texw, &texh, NULL, NULL, lumplength))
+			{
+				width = (INT16)width;
+				height = (INT16)height;
+			}
+			else
+			{
+				width = 1;
+				height = 1;
+			}
 			Z_Free(png);
 		}
 		else
diff --git a/src/r_things.c b/src/r_things.c
index c9f414ab0d2ba083d78069b63c3c6efff653983a..b595daa9cb5102720fd58d91da5f9d7c5bfe8001 100644
--- a/src/r_things.c
+++ b/src/r_things.c
@@ -308,12 +308,17 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16
 
 #ifndef NO_PNG_LUMPS
 			{
-				softwarepatch_t *png = W_CacheLumpNumPwad(wadnum, l, PU_STATIC);
+				UINT8 *png = W_CacheLumpNumPwad(wadnum, l, PU_STATIC);
 				size_t len = W_LumpLengthPwad(wadnum, l);
 
-				if (Picture_IsLumpPNG((UINT8 *)png, len))
+				if (Picture_IsLumpPNG(png, len))
 				{
-					Picture_PNGDimensions((UINT8 *)png, &width, &height, &topoffset, &leftoffset, len);
+					if (!Picture_PNGDimensions(png, &width, &height, &topoffset, &leftoffset, len))
+					{
+						Z_Free(png);
+						continue;
+					}
+
 					isPNG = true;
 				}