From 6ff3b1eda945a24f30eb7fdf32fc5c428cb55cb3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 29 Jul 2025 02:56:32 +0200 Subject: [PATCH] Revert "dont free our poly_subsectors twice" This reverts commit b2d1771e795d78696aede0b68106e2a797176875. --- src/hardware/hw_bsp.c | 29 ++++++++++++++--------------- src/hardware/hw_glob.h | 5 +++-- src/hardware/hw_main.cpp | 4 ++-- src/p_setup.c | 1 + 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 097338600..47175f81e 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -537,8 +537,6 @@ static byte* gr_polypool = NULL; static unsigned int gr_polypool_free = 0; #endif -static void HWR_Free_poly_subsectors(void); - // only between levels, clear poly pool static void HWR_Clear_Polys(void) { @@ -552,14 +550,14 @@ static void HWR_Clear_Polys(void) } // allocate pool for fast alloc of polys -void HWR_Init_PolyPool(void) +void HWR_InitPolyPool(void) { HWR_Clear_Polys(); } -void HWR_Free_PolyPool(void) +void HWR_FreePolyPool(void) { - HWR_Free_poly_subsectors(); + HWR_FreeExtraSubsectors(); HWR_Clear_Polys(); } @@ -2256,7 +2254,7 @@ bad_node: bspnum, numnodes); } -static void HWR_Free_poly_subsectors(void) +void HWR_FreeExtraSubsectors(void) { if (poly_subsectors) { @@ -2926,7 +2924,6 @@ void HWR_CreatePlanePolygons(INT32 bspnum) (void)bspnum; CONS_Debug(DBG_RENDER, "Creating polygons, please wait...\n"); - #ifdef HWR_LOADING_SCREEN ls_count = ls_percent = 0; // reset the loading status CON_Drawer(); //let the user know what we are doing @@ -2936,7 +2933,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) // reset the portal flag gl_maphasportals = 0; - HWR_Clear_Polys(); + HWR_Clear_Polys (); // Enter all vertexes into the root bounding box. // find min/max boundaries of map @@ -2947,16 +2944,18 @@ void HWR_CreatePlanePolygons(INT32 bspnum) //CONS_Debug(DBG_RENDER, "Generating subsector polygons... %d subsectors\n", numsubsectors); - HWR_Free_poly_subsectors(); - + HWR_FreeExtraSubsectors (); // allocate extra data for each subsector present in map num_alloc_poly_subsector = numsubsectors + NUM_EXTRA_SUBSECTORS; - poly_subsectors = Z_Calloc(sizeof(poly_subsector_t) * num_alloc_poly_subsector, PU_STATIC, NULL); // set all data in to 0 or NULL !!! + poly_subsectors = Z_Malloc( sizeof(poly_subsector_t) * num_alloc_poly_subsector, PU_STATIC, NULL); + // set all data in to 0 or NULL !!! + memset(poly_subsectors, 0, sizeof(poly_subsector_t) * num_alloc_poly_subsector); - wpoly_subsectors = Z_Calloc(sizeof(wpoly_t) * num_alloc_poly_subsector, PU_HWRPLANE, NULL); + wpoly_subsectors = Z_Malloc( sizeof(wpoly_t) * num_alloc_poly_subsector, PU_HWRPLANE, NULL); + memset(wpoly_subsectors, 0, sizeof(wpoly_t) * num_alloc_poly_subsector); // allocate table for back to front drawing of subsectors - /*gr_drawsubsectors = (short*)malloc(sizeof(*gr_drawsubsectors) * num_alloc_poly_subsector); + /*gr_drawsubsectors = (short*)malloc (sizeof(*gr_drawsubsectors) * num_alloc_poly_subsector); if (!gr_drawsubsectors) I_Error("couldn't malloc gr_drawsubsectors\n");*/ @@ -2967,7 +2966,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) num_poly_subsector = numsubsectors; // construct the initial convex poly that encloses the full map - wpoly_init_alloc(4, &rootp); // alloc space for 4 pts + wpoly_init_alloc( 4, &rootp); // alloc space for 4 pts #ifdef DEBUG_TRACE rootp.id1 = poly_id++; rootp.id2 = 0; @@ -2992,7 +2991,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) : (0 | NF_SUBSECTOR)), // Degenerate, sector 0 &rootp, NULL, rootbbox); - SolveTProblem(); + SolveTProblem (); AdjustSegs(); #ifdef POLYTILE diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index a993cb867..f7824669e 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -55,8 +55,9 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 extern poly_subsector_t *poly_subsectors; extern size_t num_poly_subsector; -void HWR_Init_PolyPool(void); -void HWR_Free_PolyPool(void); +void HWR_InitPolyPool(void); +void HWR_FreePolyPool(void); +void HWR_FreeExtraSubsectors(void); // -------- // hw_cache.c diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index b94e21790..6850e6e29 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5943,7 +5943,7 @@ void HWR_Startup(void) CONS_Printf("HWR_Startup()...\n"); textureformat = patchformat = GL_TEXFMT_RGBA; - HWR_Init_PolyPool(); + HWR_InitPolyPool(); HWR_InitMapTextures(); HWR_InitMD2(); @@ -6036,7 +6036,7 @@ static void COM_HWR_glinfo(void) void HWR_Shutdown(void) { CONS_Printf("HWR_Shutdown()\n"); - HWR_Free_PolyPool(); + HWR_FreePolyPool(); HWR_FreeMapTextures(); GL_FlushScreenTextures(); #ifdef USE_FBO_OGL diff --git a/src/p_setup.c b/src/p_setup.c index b406740dd..7f6ecc69d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2996,6 +2996,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) #ifdef HWRENDER // not win32 only 19990829 by Kin if (rendermode == render_opengl) { + HWR_FreeExtraSubsectors(); // Create plane polygons. HWR_LoadLevel(reloadinggamestate); }