From: Mathnerd314 Date: Sat, 27 Feb 2010 21:56:12 +0000 (+0000) Subject: Fix frame out of range error for -O2 release build (may or may not fix on other syste... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9ba1d17e70aae16be8bf20b413b155ce905195b7;p=supertux.git Fix frame out of range error for -O2 release build (may or may not fix on other systems/compilers) SVN-Revision: 6435 --- diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index abf3c93de..16e1adaa0 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -87,12 +87,12 @@ Sprite::set_action_continued(const std::string& name) } action = newaction; - if(frame >= get_frames()) { - frame = fmodf(frame, get_frames()); - - if (animation_loops > 0) animation_loops--; + while(frame >= get_frames()) { + frame -= get_frames(); + animation_loops--; if(animation_done()) frame = get_frames()-1; + break; } } @@ -105,20 +105,22 @@ Sprite::animation_done() void Sprite::update() { - if(animation_done()) + if(animation_done()) { + frame = get_frames()-1; return; + } float frame_inc = action->fps * (game_time - last_ticks); last_ticks = game_time; frame += frame_inc; - if(frame >= get_frames()) { - frame = fmodf(frame, get_frames()); - + while(frame >= get_frames()) { + frame -= get_frames(); animation_loops--; if(animation_done()) frame = get_frames()-1; + break; } } @@ -130,7 +132,7 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer, update(); if((int)frame >= get_frames() || (int)frame < 0) - log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; + log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; else { context.set_drawing_effect(effect); context.draw_surface(action->surfaces[(int)frame], @@ -167,7 +169,7 @@ Sprite::get_width() const { if((int)frame >= get_frames() || (int)frame < 0) { - log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; + log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; return 0; } else @@ -181,7 +183,7 @@ Sprite::get_height() const { if((int)frame >= get_frames() || (int)frame < 0) { - log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; + log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl; return 0; } else