From e73f33a67785994fa0790828e71fbb6aca003d4a Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 16 Jan 2024 14:34:38 -0300 Subject: [PATCH] Fix build warnings --- src/r_picformats.c | 16 ++++++++++------ src/r_segs.c | 10 ++++------ src/r_textures.c | 28 +++++++++++++++++++++------- src/r_things.c | 11 ++++++++--- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/r_picformats.c b/src/r_picformats.c index 8117d08d5..7d7f1198d 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 d8267ea6f..ae46a4aeb 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 2d38133a3..de62c1511 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 c9f414ab0..b595daa9c 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; }