Skip to content

Commit

Permalink
Fix crash if Animation is not explicitly assigned in MODELDEF.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa the Magician authored and coelckers committed Nov 24, 2022
1 parent ffdd0a1 commit b002d5b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/common/models/model.h
Expand Up @@ -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<TRS>* AttachAnimationData() { return nullptr; };
virtual const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* bones, int index) { return {}; };
virtual const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>* animationData, DBoneComponents* bones, int index) { return {}; };

void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; }
IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; }
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/model_iqm.h
Expand Up @@ -116,7 +116,7 @@ class IQMModel : public FModel
void BuildVertexBuffer(FModelRenderer* renderer) override;
void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override;
const TArray<TRS>* AttachAnimationData() override;
const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* bones, int index) override;
const TArray<VSMatrix> CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>* animationData, DBoneComponents* bones, int index) override;

private:
void LoadGeometry();
Expand Down
6 changes: 3 additions & 3 deletions src/common/models/models_iqm.cpp
Expand Up @@ -514,9 +514,9 @@ const TArray<TRS>* IQMModel::AttachAnimationData()
return &TRSData;
}

const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>& animationData, DBoneComponents* boneComponentData, int index)
const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double inter, const TArray<TRS>* animationData, DBoneComponents* boneComponentData, int index)
{
const TArray<TRS>& animationFrames = &animationData ? animationData : TRSData;
const TArray<TRS>& animationFrames = animationData ? *animationData : TRSData;
if (Joints.Size() > 0)
{
int numbones = Joints.Size();
Expand Down Expand Up @@ -604,4 +604,4 @@ const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, double i
return bones;
}
return {};
}
}
7 changes: 3 additions & 4 deletions src/r_data/models.cpp
Expand Up @@ -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<TRS>* animationData = nullptr;

bool nextFrame = smfNext && modelframe != modelframenext;

Expand All @@ -381,11 +380,11 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
if (animationid >= 0)
{
FModel* animation = Models[animationid];
animationData = animation->AttachAnimationData();
const TArray<TRS>* 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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b002d5b

Please sign in to comment.