Skip to content

Commit

Permalink
Fix crash on GotoNext/PreviousFrameWithSameTagCommands when there is …
Browse files Browse the repository at this point in the history
…no tag

Some other minor changes as avoid casting int <-> frame_t because now
frame_t is a typedef (some time ago it was a class and those cast were
necessary).

Related to #887
  • Loading branch information
dacap committed Dec 5, 2015
1 parent 45e4c46 commit f389a2e
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/app/commands/cmd_goto_frame.cpp
Expand Up @@ -53,7 +53,7 @@ class GotoFirstFrameCommand : public GotoCommand {

protected:
frame_t onGetFrame(Editor* editor) override {
return frame_t(0);
return 0;
}
};

Expand All @@ -67,11 +67,9 @@ class GotoPreviousFrameCommand : public GotoCommand {
protected:
frame_t onGetFrame(Editor* editor) override {
frame_t frame = editor->frame();
frame_t last = editor->sprite()->lastFrame();

if (frame > frame_t(0))
return frame-1;
else
return editor->sprite()->lastFrame();
return (frame > 0 ? frame-1: last);
}
};

Expand All @@ -84,10 +82,9 @@ class GotoNextFrameCommand : public GotoCommand {
protected:
frame_t onGetFrame(Editor* editor) override {
frame_t frame = editor->frame();
if (frame < editor->sprite()->lastFrame())
return frame+1;
else
return frame_t(0);
frame_t last = editor->sprite()->lastFrame();

return (frame < last ? frame+1: 0);
}
};

Expand All @@ -99,15 +96,12 @@ class GotoNextFrameWithSameTagCommand : public GotoCommand {

protected:
frame_t onGetFrame(Editor* editor) override {
Sprite* sprite = editor->sprite();
frame_t currentFrame = editor->frame();
FrameTag* tag = get_animation_tag(sprite, currentFrame);
frame_t frameToGo = currentFrame + frame_t(1);

if (frameToGo > tag->toFrame())
frameToGo = tag->fromFrame();
frame_t frame = editor->frame();
FrameTag* tag = get_animation_tag(editor->sprite(), frame);
frame_t first = (tag ? tag->fromFrame(): 0);
frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());

return frameToGo;
return (frame < last ? frame+1: first);
}
};

Expand All @@ -119,15 +113,12 @@ class GotoPreviousFrameWithSameTagCommand : public GotoCommand {

protected:
frame_t onGetFrame(Editor* editor) override {
Sprite* sprite = editor->sprite();
frame_t currentFrame = editor->frame();
FrameTag* tag = get_animation_tag(sprite, currentFrame);
frame_t frameToGo = currentFrame - frame_t(1);

if (frameToGo < tag->fromFrame())
frameToGo = tag->toFrame();
frame_t frame = editor->frame();
FrameTag* tag = get_animation_tag(editor->sprite(), frame);
frame_t first = (tag ? tag->fromFrame(): 0);
frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());

return frameToGo;
return (frame > first ? frame-1: last);
}
};

Expand All @@ -151,8 +142,7 @@ class GotoFrameCommand : public GotoCommand {
Command* clone() const override { return new GotoFrameCommand(*this); }

protected:
void onLoadParams(const Params& params) override
{
void onLoadParams(const Params& params) override {
std::string frame = params.get("frame");
if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10);
else m_frame = 0;
Expand Down

0 comments on commit f389a2e

Please sign in to comment.