From 34addf6031503a4d22a9c440d967ae81ffee4c6a Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Thu, 16 Feb 2023 19:17:35 +0300 Subject: [PATCH] gl: more animation checks --- src/game/renders/opengl/r_map.pas | 18 +++++++++++----- src/game/renders/opengl/r_textures.pas | 30 ++++++++++++++++++-------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 5513d68..914087d 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -536,8 +536,8 @@ implementation r_Common_SetLoading(_lc[I_LOAD_TEXTURES], n); for i := 0 to n - 1 do begin - txt.anim := DefaultAnimInfo; RenTextures[i].tex := nil; + RenTextures[i].anim := DefaultAnimInfo; case Textures[i].TextureName of TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER; TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1; @@ -545,12 +545,18 @@ implementation else RenTextures[i].spec := 0; RenTextures[i].tex := r_Textures_LoadMultiTextFromFile(Textures[i].FullName, txt, []); - if RenTextures[i].tex = nil then - e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]) - else + if RenTextures[i].tex <> nil then + begin + RenTextures[i].anim := txt.anim; r_Common_StepLoading(1); + end + else + begin + e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]); + end; end; - RenTextures[i].anim := txt.anim; + ASSERT(RenTextures[i].anim.frames > 0); + ASSERT(RenTextures[i].anim.delay > 0); end; end; if gMapInfo.SkyFullName <> '' then @@ -578,7 +584,9 @@ implementation ASSERT(p <> nil); if p.FCurTexture >= 0 then begin + ASSERT(p.FCurTexture <= High(p.TextureIDs)); Texture := p.TextureIDs[p.FCurTexture].Texture; + ASSERT(Texture <= High(RenTextures)); t := RenTextures[Texture].tex; if (RenTextures[Texture].spec = 0) or (t <> nil) then begin diff --git a/src/game/renders/opengl/r_textures.pas b/src/game/renders/opengl/r_textures.pas index b98c0d3..f66708f 100644 --- a/src/game/renders/opengl/r_textures.pas +++ b/src/game/renders/opengl/r_textures.pas @@ -645,7 +645,7 @@ implementation end; function r_Textures_LoadTextFromMemory (data: Pointer; size: LongInt; var txt: TAnimTextInfo): Boolean; - var cfg: TConfig; + var cfg: TConfig; text: TAnimTextInfo; begin result := false; if data <> nil then @@ -653,15 +653,27 @@ implementation cfg := TConfig.CreateMem(data, size); if cfg <> nil then begin - txt.name := cfg.ReadStr('', 'resource', ''); - txt.w := MAX(0, cfg.ReadInt('', 'framewidth', 0)); - txt.h := MAX(0, cfg.ReadInt('', 'frameheight', 0)); - txt.anim.loop := true; - txt.anim.delay := MAX(0, cfg.ReadInt('', 'waitcount', 0)); - txt.anim.frames := MAX(0, cfg.ReadInt('', 'framecount', 0)); - txt.anim.back := cfg.ReadBool('', 'backanim', false); + text.name := cfg.ReadStr('', 'resource', ''); + text.w := cfg.ReadInt('', 'framewidth', 0); + text.h := cfg.ReadInt('', 'frameheight', 0); + text.anim.loop := true; + text.anim.delay := cfg.ReadInt('', 'waitcount', 0); + text.anim.frames := cfg.ReadInt('', 'framecount', 0); + text.anim.back := cfg.ReadBool('', 'backanim', false); + if text.w <= 0 then e_LogWritefln('Warning: bad animation width %s for %s', [text.w, text.name]); + if text.h <= 0 then e_LogWritefln('Warning: bad animation height %s for %s', [text.h, text.name]); + if text.anim.delay <= 0 then e_LogWritefln('Warning: bad animation delay %s for %s', [text.anim.delay, text.name]); + if text.anim.frames <= 0 then e_LogWritefln('Warning: bad animation frame count %s for %s', [text.anim.frames, text.name]); + text.w := MAX(0, text.w); + text.h := MAX(0, text.h); + text.anim.delay := MAX(1, text.anim.delay); + text.anim.frames := MAX(1, text.anim.frames); cfg.Free; - result := (txt.name <> '') and (txt.w > 0) and (txt.h > 0) and (txt.anim.delay > 0) and (txt.anim.frames > 0); + if (txt.name <> '') and (txt.w > 0) and (txt.h > 0) and (txt.anim.delay > 0) and (txt.anim.frames > 0) then + begin + txt := text; + result := true; + end; end; end; end; -- 2.29.2