Commit c7b99378 by MCMic Committed by Rémi Verschelde

Temporary work around a crash for the release

(cherry picked from commit efb370c9)
parent a09b7f8c
Pipeline #6423556 passed with stage
in 5 minutes 48 seconds
......@@ -2238,7 +2238,7 @@ void Person::DoAnimations()
animCurrent = animTarget;
frameTarget++;
if (animTarget == removeknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
if (animTarget == removeknifeanim && currentFrame().label == 5) {
for (unsigned i = 0; i < weapons.size(); i++) {
if (weapons[i].owner == -1) {
if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
......@@ -2254,7 +2254,7 @@ void Person::DoAnimations()
}
}
if (animTarget == crouchremoveknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
if (animTarget == crouchremoveknifeanim && currentFrame().label == 5) {
for (unsigned i = 0; i < weapons.size(); i++) {
bool willwork = true;
if (weapons[i].owner != -1) {
......@@ -2340,7 +2340,7 @@ void Person::DoAnimations()
}
}
if (animCurrent == drawleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
if (animCurrent == drawleftanim && currentFrame().label == 5) {
if (weaponactive == -1) {
weaponactive = 0;
} else if (weaponactive == 0) {
......@@ -3912,7 +3912,7 @@ void Person::DoAnimations()
}
//Animation end
if (frameTarget > int(Animation::animations[animCurrent].frames.size()) - 1) {
if (frameTarget >= int(Animation::animations[animCurrent].frames.size())) {
frameTarget = 0;
if (wasStop()) {
animTarget = getIdle();
......@@ -4385,6 +4385,11 @@ void Person::DoAnimations()
frameCurrent = frameTarget;
target = 1;
}
if (frameCurrent >= int(Animation::animations[animCurrent].frames.size())) {
frameCurrent = Animation::animations[animCurrent].frames.size() - 1;
}
oldrot = rot;
rot = targetrot * target;
yaw += rot - oldrot;
......@@ -4393,9 +4398,7 @@ void Person::DoAnimations()
oldrot = 0;
targetrot = 0;
}
if (frameCurrent >= int(Animation::animations[animCurrent].frames.size())) {
frameCurrent = Animation::animations[animCurrent].frames.size() - 1;
}
if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
//Old rotates
for (unsigned i = 0; i < skeleton.joints.size(); i++) {
......
......@@ -324,8 +324,32 @@ public:
inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
AnimationFrame& currentFrame() {
/* FIXME - try/catch is a temporary fix to avoid crashes but game logic should be fixed instead */
try {
return Animation::animations.at(animCurrent).frames.at(frameCurrent);
} catch (const std::exception& error) {
/* Most likely frameCurrent is too big, work around */
if ((unsigned)frameCurrent >=
Animation::animations.at(animCurrent).frames.size()) {
frameCurrent = Animation::animations.at(animCurrent).frames.size() - 1;
}
return Animation::animations.at(animCurrent).frames.back();
}
}
AnimationFrame& targetFrame() {
/* FIXME - try/catch is a temporary fix to avoid crashes but game logic should be fixed instead */
try {
return Animation::animations.at(animTarget).frames.at(frameTarget);
} catch (const std::exception& error) {
/* Most likely frameTarget is too big, work around */
if ((unsigned)frameTarget >=
Animation::animations.at(animTarget).frames.size()) {
frameTarget = Animation::animations.at(animTarget).frames.size() - 1;
}
return Animation::animations.at(animTarget).frames.back();
}
}
void setProportions(float head, float body, float arms, float legs);
float getProportion(int part) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment