From: Axel Isouard Date: Sat, 28 Jul 2012 08:09:06 +0000 (+0200) Subject: Fixed memory issues, map is now loading perfectly, having to make the lightgrid working X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c6dde92f13c5c53caa509ff57101abae19fb435c;p=xonotic%2Fdarkplaces.git Fixed memory issues, map is now loading perfectly, having to make the lightgrid working --- diff --git a/model_brush.c b/model_brush.c index ac713335..558624be 100644 --- a/model_brush.c +++ b/model_brush.c @@ -7662,16 +7662,11 @@ static void Mod_JKBSP_LoadVertices(lump_t *l) loadmodel->brushjk.data_normal3f = loadmodel->brushjk.data_vertex3f + count * 3; loadmodel->brushjk.data_texcoordtexture2f = loadmodel->brushjk.data_normal3f + count * 3; - loadmodel->brushjk.data_texcoordlightmap2f = (float **)Mem_Alloc(loadmodel->mempool, MAX_LIGHTMAPS); - loadmodel->brushjk.data_texcoordlightmap2f[0] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 2); - loadmodel->brushjk.data_texcoordlightmap2f[1] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 2); - loadmodel->brushjk.data_texcoordlightmap2f[2] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 2); - loadmodel->brushjk.data_texcoordlightmap2f[3] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 2); - loadmodel->brushjk.data_color4f = (float **)Mem_Alloc(loadmodel->mempool, MAX_LIGHTMAPS); - loadmodel->brushjk.data_color4f[0] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 4); - loadmodel->brushjk.data_color4f[1] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 4); - loadmodel->brushjk.data_color4f[2] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 4); - loadmodel->brushjk.data_color4f[3] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 4); + for (j = 0; j < MAX_LIGHTMAPS; j++) + { + loadmodel->brushjk.data_texcoordlightmap2f[j] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 2); + loadmodel->brushjk.data_color4f[j] = (float *)Mem_Alloc(loadmodel->mempool, count * sizeof(float) * 4); + } for (i = 0; i < count; i++, in++) { @@ -7728,7 +7723,7 @@ static void Mod_JKBSP_LoadVertices(lump_t *l) else { for (j = 0; j < MAX_LIGHTMAPS; j++) - { + { loadmodel->brushjk.data_color4f[j][i * 4 + 0] = in->color4ub[j][0] * (1.0f / 255.0f); loadmodel->brushjk.data_color4f[j][i * 4 + 1] = in->color4ub[j][1] * (1.0f / 255.0f); loadmodel->brushjk.data_color4f[j][i * 4 + 2] = in->color4ub[j][2] * (1.0f / 255.0f); @@ -7982,6 +7977,7 @@ static void Mod_JKBSP_LoadLightmaps(lump_t *l, lump_t *faceslump) mergedrowsxcolumns = 1 << powerxy; loadmodel->brushjk.num_mergedlightmaps = (realcount + (1 << powerxy) - 1) >> powerxy; + Con_Printf("mergedlightmaps = %d\n", loadmodel->brushjk.num_mergedlightmaps); loadmodel->brushjk.data_lightmaps = (rtexture_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brushjk.num_mergedlightmaps * sizeof(rtexture_t *)); if (loadmodel->brushjk.deluxemapping) loadmodel->brushjk.data_deluxemaps = (rtexture_t **)Mem_Alloc(loadmodel->mempool, loadmodel->brushjk.num_mergedlightmaps * sizeof(rtexture_t *)); @@ -8579,8 +8575,14 @@ static void Mod_JKBSP_LoadFaces(lump_t *l) loadmodel->brushjk.data_vertex3f = NULL; loadmodel->brushjk.data_normal3f = NULL; loadmodel->brushjk.data_texcoordtexture2f = NULL; - loadmodel->brushjk.data_texcoordlightmap2f = NULL; - loadmodel->brushjk.data_color4f = NULL; + + for (i = 0; i < MAX_LIGHTMAPS; i++) + { + Mem_Free(loadmodel->brushjk.data_texcoordlightmap2f[i]); + Mem_Free(loadmodel->brushjk.data_color4f[i]); + loadmodel->brushjk.data_texcoordlightmap2f[i] = NULL; + loadmodel->brushjk.data_color4f[i] = NULL; + } // free the no longer needed triangle data loadmodel->brushjk.num_triangles = 0; if (loadmodel->brushjk.data_element3i) diff --git a/model_shared.h b/model_shared.h index 94112545..151c8128 100644 --- a/model_shared.h +++ b/model_shared.h @@ -946,8 +946,8 @@ typedef struct model_brushjk_s float *data_vertex3f; float *data_normal3f; float *data_texcoordtexture2f; - float **data_texcoordlightmap2f; - float **data_color4f; + float *data_texcoordlightmap2f[MAX_LIGHTMAPS]; + float *data_color4f[MAX_LIGHTMAPS]; // freed after loading! int num_triangles;