Skip to content

Commit

Permalink
Temporary work around a crash for the release
Browse files Browse the repository at this point in the history
(cherry picked from commit efb370c)
  • Loading branch information
MCMic authored and akien-mga committed Feb 11, 2017
1 parent a09b7f8 commit c7b9937
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
17 changes: 10 additions & 7 deletions Source/Objects/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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++) {
Expand Down
28 changes: 26 additions & 2 deletions Source/Objects/Person.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,32 @@ class Person : public enable_shared_from_this<Person>
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;
Expand Down

0 comments on commit c7b9937

Please sign in to comment.