From ffa53eb3c47f0311b77d994fb6e4d6fe8e8f9638 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 23 Oct 2016 20:33:14 +0000 Subject: [PATCH] Page in textures before caching them Some custom levels attempt to use texture overrides that reference textures that are not yet paged in. It is not legal to access the data of a paged-out texture, but ogl_loadbmtexture_f attempted to access it anyway, causing a crash. Page in the texture before calling ogl_loadbmtexture_f. Old versions of the engine would have cached garbage data when this happened. Reported-by: kreator Fixes: 3c20c24ac0cc2d994f271a53ebd6e2f20356aa78 ("Disable piggy_bitmap_page_out_all") --- similar/arch/ogl/ogl.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/similar/arch/ogl/ogl.cpp b/similar/arch/ogl/ogl.cpp index 31a13461e..bb88bb6ad 100644 --- a/similar/arch/ogl/ogl.cpp +++ b/similar/arch/ogl/ogl.cpp @@ -513,7 +513,11 @@ void ogl_cache_level_textures(void) ogl_cache_weapon_textures(ri.weapon_type); } if (objp->rtype.pobj_info.tmap_override != -1) - ogl_loadbmtexture(GameBitmaps[Textures[objp->rtype.pobj_info.tmap_override].index], 1); + { + auto &t = Textures[objp->rtype.pobj_info.tmap_override]; + PIGGY_PAGE_IN(t); + ogl_loadbmtexture(GameBitmaps[t.index], 1); + } else ogl_cache_polymodel_textures(objp->rtype.pobj_info.model_num); } @@ -1751,7 +1755,8 @@ unsigned char decodebuf[1024*1024]; void ogl_loadbmtexture_f(grs_bitmap &rbm, int texfilt, bool texanis, bool edgepad) { - + assert(!(rbm.bm_flags & BM_FLAG_PAGED_OUT)); + assert(rbm.bm_data); grs_bitmap *bm = &rbm; while (bm->bm_parent) bm=bm->bm_parent;