Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashing segfault when calling: app.command.CloseFile() or app.command.GotoPreviousTab() , in --batch mode (fix #4352) #4421

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/commands/cmd_close_file.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -35,6 +36,8 @@ class CloseFileCommand : public Command {

bool onEnabled(Context* context) override {
Workspace* workspace = App::instance()->workspace();
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
return false;
WorkspaceView* view = workspace->activeView();
return (view != nullptr);
}
Expand Down Expand Up @@ -62,6 +65,8 @@ class CloseAllFilesCommand : public Command {

void onExecute(Context* context) override {
Workspace* workspace = App::instance()->workspace();
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
return;

// Collect all document views
DocViews docViews;
Expand Down
3 changes: 3 additions & 0 deletions src/app/commands/cmd_duplicate_view.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -35,6 +36,8 @@ DuplicateViewCommand::DuplicateViewCommand()
bool DuplicateViewCommand::onEnabled(Context* context)
{
Workspace* workspace = App::instance()->workspace();
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
return false;
WorkspaceView* view = workspace->activeView();
return (view != nullptr);
}
Expand Down
11 changes: 9 additions & 2 deletions src/app/commands/cmd_goto_tab.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -30,7 +31,10 @@ GotoNextTabCommand::GotoNextTabCommand()

bool GotoNextTabCommand::onEnabled(Context* context)
{
return App::instance()->workspace()->canSelectOtherTab();
Workspace* workspace = App::instance()->workspace();
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
return false;
return workspace->canSelectOtherTab();
}

void GotoNextTabCommand::onExecute(Context* context)
Expand All @@ -54,7 +58,10 @@ GotoPreviousTabCommand::GotoPreviousTabCommand()

bool GotoPreviousTabCommand::onEnabled(Context* context)
{
return App::instance()->workspace()->canSelectOtherTab();
Workspace* workspace = App::instance()->workspace();
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
return false;
return workspace->canSelectOtherTab();
}

void GotoPreviousTabCommand::onExecute(Context* context)
Expand Down