Fix crash on GotoNext/PreviousFrameWithSameTagCommands when there is 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
This commit is contained in:
David Capello 2015-12-05 15:42:12 -03:00
parent 45e4c4656a
commit f389a2ec23

View File

@ -53,7 +53,7 @@ public:
protected: protected:
frame_t onGetFrame(Editor* editor) override { frame_t onGetFrame(Editor* editor) override {
return frame_t(0); return 0;
} }
}; };
@ -67,11 +67,9 @@ public:
protected: protected:
frame_t onGetFrame(Editor* editor) override { frame_t onGetFrame(Editor* editor) override {
frame_t frame = editor->frame(); frame_t frame = editor->frame();
frame_t last = editor->sprite()->lastFrame();
if (frame > frame_t(0)) return (frame > 0 ? frame-1: last);
return frame-1;
else
return editor->sprite()->lastFrame();
} }
}; };
@ -84,10 +82,9 @@ public:
protected: protected:
frame_t onGetFrame(Editor* editor) override { frame_t onGetFrame(Editor* editor) override {
frame_t frame = editor->frame(); frame_t frame = editor->frame();
if (frame < editor->sprite()->lastFrame()) frame_t last = editor->sprite()->lastFrame();
return frame+1;
else return (frame < last ? frame+1: 0);
return frame_t(0);
} }
}; };
@ -99,15 +96,12 @@ public:
protected: protected:
frame_t onGetFrame(Editor* editor) override { frame_t onGetFrame(Editor* editor) override {
Sprite* sprite = editor->sprite(); frame_t frame = editor->frame();
frame_t currentFrame = editor->frame(); FrameTag* tag = get_animation_tag(editor->sprite(), frame);
FrameTag* tag = get_animation_tag(sprite, currentFrame); frame_t first = (tag ? tag->fromFrame(): 0);
frame_t frameToGo = currentFrame + frame_t(1); frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());
if (frameToGo > tag->toFrame()) return (frame < last ? frame+1: first);
frameToGo = tag->fromFrame();
return frameToGo;
} }
}; };
@ -119,15 +113,12 @@ public:
protected: protected:
frame_t onGetFrame(Editor* editor) override { frame_t onGetFrame(Editor* editor) override {
Sprite* sprite = editor->sprite(); frame_t frame = editor->frame();
frame_t currentFrame = editor->frame(); FrameTag* tag = get_animation_tag(editor->sprite(), frame);
FrameTag* tag = get_animation_tag(sprite, currentFrame); frame_t first = (tag ? tag->fromFrame(): 0);
frame_t frameToGo = currentFrame - frame_t(1); frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());
if (frameToGo < tag->fromFrame()) return (frame > first ? frame-1: last);
frameToGo = tag->toFrame();
return frameToGo;
} }
}; };
@ -151,8 +142,7 @@ public:
Command* clone() const override { return new GotoFrameCommand(*this); } Command* clone() const override { return new GotoFrameCommand(*this); }
protected: protected:
void onLoadParams(const Params& params) override void onLoadParams(const Params& params) override {
{
std::string frame = params.get("frame"); std::string frame = params.get("frame");
if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10); if (!frame.empty()) m_frame = strtol(frame.c_str(), NULL, 10);
else m_frame = 0; else m_frame = 0;