From 1adaf750da517c3a4862bf9bfb02af42d16e2016 Mon Sep 17 00:00:00 2001 From: mathnerd314 Date: Sat, 27 Feb 2010 21:56:12 +0000 Subject: [PATCH] Fix frame out of range error for -O2 release build (may or may not fix on other systems/compilers) git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6435 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/sprite/sprite.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 -- 2.11.0