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

This commit is contained in:
Gaspar Capello 2024-04-17 15:16:01 -03:00 committed by David Capello
parent 02e8d97eed
commit 1896483458
3 changed files with 17 additions and 2 deletions

View File

@ -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
@ -35,6 +36,8 @@ protected:
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);
}
@ -62,6 +65,8 @@ protected:
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;

View File

@ -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
@ -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);
}

View File

@ -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
@ -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)
@ -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)