From b002d5b8ec076706122714fdc3c682f5a3eb5533 Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Thu, 24 Nov 2022 17:49:30 +0100 Subject: [PATCH] Fix crash if Animation is not explicitly assigned in MODELDEF. --- src/common/models/model.h | 2 +- src/common/models/model_iqm.h | 2 +- src/common/models/models_iqm.cpp | 6 +++--- src/r_data/models.cpp | 7 +++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/models/model.h b/src/common/models/model.h index 6084e540757..dc4d644764b 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -77,7 +77,7 @@ class FModel virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) = 0; virtual float getAspectFactor(float vscale) { return 1.f; } virtual const TArray* AttachAnimationData() { return nullptr; }; - virtual const TArray CalculateBones(int frame1, int frame2, double inter, const TArray& animationData, DBoneComponents* bones, int index) { return {}; }; + virtual const TArray CalculateBones(int frame1, int frame2, double inter, const TArray* animationData, DBoneComponents* bones, int index) { return {}; }; void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } diff --git a/src/common/models/model_iqm.h b/src/common/models/model_iqm.h index cd87a78f328..3ab9566895b 100644 --- a/src/common/models/model_iqm.h +++ b/src/common/models/model_iqm.h @@ -116,7 +116,7 @@ class IQMModel : public FModel void BuildVertexBuffer(FModelRenderer* renderer) override; void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override; const TArray* AttachAnimationData() override; - const TArray CalculateBones(int frame1, int frame2, double inter, const TArray& animationData, DBoneComponents* bones, int index) override; + const TArray CalculateBones(int frame1, int frame2, double inter, const TArray* animationData, DBoneComponents* bones, int index) override; private: void LoadGeometry(); diff --git a/src/common/models/models_iqm.cpp b/src/common/models/models_iqm.cpp index 514fb2833c9..d61ad9e6720 100644 --- a/src/common/models/models_iqm.cpp +++ b/src/common/models/models_iqm.cpp @@ -514,9 +514,9 @@ const TArray* IQMModel::AttachAnimationData() return &TRSData; } -const TArray IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray& animationData, DBoneComponents* boneComponentData, int index) +const TArray IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray* animationData, DBoneComponents* boneComponentData, int index) { - const TArray& animationFrames = &animationData ? animationData : TRSData; + const TArray& animationFrames = animationData ? *animationData : TRSData; if (Joints.Size() > 0) { int numbones = Joints.Size(); @@ -604,4 +604,4 @@ const TArray IQMModel::CalculateBones(int frame1, int frame2, double i return bones; } return {}; -} \ No newline at end of file +} diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index fd1fa27a092..8ed3e57f2c4 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -365,7 +365,6 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr auto& ssids = surfaceskinids.Size() > 0 ? surfaceskinids : smf->surfaceskinIDs; auto ssidp = (unsigned)(i * MD3_MAX_SURFACES) < ssids.Size() ? &ssids[i * MD3_MAX_SURFACES] : nullptr; - const TArray* animationData = nullptr; bool nextFrame = smfNext && modelframe != modelframenext; @@ -381,11 +380,11 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr if (animationid >= 0) { FModel* animation = Models[animationid]; - animationData = animation->AttachAnimationData(); + const TArray* animationData = animation->AttachAnimationData(); if (!(smf->flags & MDL_MODELSAREATTACHMENTS) || evaluatedSingle == false) { - boneData = animation->CalculateBones(modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : 0.f, *animationData, actor->boneComponentData, i); + boneData = animation->CalculateBones(modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : 0.f, animationData, actor->boneComponentData, i); boneStartingPosition = renderer->SetupFrame(animation, 0, 0, 0, boneData, -1); evaluatedSingle = true; } @@ -394,7 +393,7 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr { if (!(smf->flags & MDL_MODELSAREATTACHMENTS) || evaluatedSingle == false) { - boneData = mdl->CalculateBones(modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : 0.f, *animationData, actor->boneComponentData, i); + boneData = mdl->CalculateBones(modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : 0.f, nullptr, actor->boneComponentData, i); boneStartingPosition = renderer->SetupFrame(mdl, 0, 0, 0, boneData, -1); evaluatedSingle = true; }