From fabb58e0eaa6e48ec389c41019ee1a65d2d1685e Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 16 Mar 2014 21:56:18 -0300 Subject: [PATCH] Fix crash in "go to" commands, don't access to null layer --- src/app/commands/cmd_goto_layer.cpp | 39 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/commands/cmd_goto_layer.cpp b/src/app/commands/cmd_goto_layer.cpp index 77ad3b550..b5af2b4c1 100644 --- a/src/app/commands/cmd_goto_layer.cpp +++ b/src/app/commands/cmd_goto_layer.cpp @@ -32,7 +32,22 @@ namespace app { -class GotoPreviousLayerCommand : public Command { +class GotoCommand : public Command { +public: + GotoCommand(const char* short_name, const char* friendly_name, CommandFlags flags) + : Command(short_name, friendly_name, flags) { + } + +protected: + void updateStatusBar(DocumentLocation& location) { + if (location.layer() != NULL) + StatusBar::instance() + ->setStatusText(1000, "Layer `%s' selected", + location.layer()->getName().c_str()); + } +}; + +class GotoPreviousLayerCommand : public GotoCommand { public: GotoPreviousLayerCommand(); Command* clone() { return new GotoPreviousLayerCommand(*this); } @@ -43,9 +58,9 @@ protected: }; GotoPreviousLayerCommand::GotoPreviousLayerCommand() - : Command("GotoPreviousLayer", - "Goto Previous Layer", - CmdUIOnlyFlag) + : GotoCommand("GotoPreviousLayer", + "Goto Previous Layer", + CmdUIOnlyFlag) { } @@ -71,12 +86,10 @@ void GotoPreviousLayerCommand::onExecute(Context* context) current_editor->setLayer(location.layer()); current_editor->flashCurrentLayer(); - StatusBar::instance() - ->setStatusText(1000, "Layer `%s' selected", - location.layer()->getName().c_str()); + updateStatusBar(location); } -class GotoNextLayerCommand : public Command { +class GotoNextLayerCommand : public GotoCommand { public: GotoNextLayerCommand(); Command* clone() { return new GotoNextLayerCommand(*this); } @@ -87,9 +100,9 @@ protected: }; GotoNextLayerCommand::GotoNextLayerCommand() - : Command("GotoNextLayer", - "Goto Next Layer", - CmdUIOnlyFlag) + : GotoCommand("GotoNextLayer", + "Goto Next Layer", + CmdUIOnlyFlag) { } @@ -115,9 +128,7 @@ void GotoNextLayerCommand::onExecute(Context* context) current_editor->setLayer(location.layer()); current_editor->flashCurrentLayer(); - StatusBar::instance() - ->setStatusText(1000, "Layer `%s' selected", - location.layer()->getName().c_str()); + updateStatusBar(location); } Command* CommandFactory::createGotoPreviousLayerCommand()