mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
Fix exception during palette changes while editor state is MovingPixelsState
Before this fix a console error appeared during a setTransparentIndex or setPalette execution (or other functions in the ColorBar class) while some selected portion of the image was transformed (MovingPixelsState). Bug reported: https://community.aseprite.org/t/5288
This commit is contained in:
parent
27273e5529
commit
5e172d81ee
38
src/app/inline_command_execution.h
Normal file
38
src/app/inline_command_execution.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2021 Igara Studio S.A.
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
|
||||
#ifndef APP_INLINE_COMMAND_EXECUTION_H_INCLUDED
|
||||
#define APP_INLINE_COMMAND_EXECUTION_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
namespace app {
|
||||
|
||||
// This class was created to simulate a Command Execution behavior.
|
||||
// Particularly, this class is used in color_bar.cpp
|
||||
// (solved issue: locked ContextWriter during a ui palette changes
|
||||
// while the current editor state is MovingPixelsState)
|
||||
|
||||
class InlineCommandExecution : public Command {
|
||||
public:
|
||||
InlineCommandExecution(Context* ctx)
|
||||
: Command("", CmdUIOnlyFlag)
|
||||
, m_context(ctx)
|
||||
{
|
||||
CommandExecutionEvent ev(this);
|
||||
m_context->BeforeCommandExecution(ev);
|
||||
}
|
||||
~InlineCommandExecution()
|
||||
{
|
||||
CommandExecutionEvent ev(this);
|
||||
m_context->AfterCommandExecution(ev);
|
||||
}
|
||||
private:
|
||||
Context* m_context;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -34,6 +34,7 @@
|
||||
#include "app/doc_undo.h"
|
||||
#include "app/i18n/strings.h"
|
||||
#include "app/ini_file.h"
|
||||
#include "app/inline_command_execution.h"
|
||||
#include "app/modules/editors.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/modules/palettes.h"
|
||||
@ -787,6 +788,7 @@ void ColorBar::onRemapPalButtonClick()
|
||||
// Create remap from m_oldPalette to the current palette
|
||||
Remap remap(1);
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Sprite* sprite = writer.sprite();
|
||||
ASSERT(sprite);
|
||||
@ -808,6 +810,7 @@ void ColorBar::onRemapPalButtonClick()
|
||||
}
|
||||
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Sprite* sprite = writer.sprite();
|
||||
if (sprite) {
|
||||
@ -862,6 +865,7 @@ void ColorBar::onRemapTilesButtonClick()
|
||||
{
|
||||
COLOR_BAR_TRACE("remapTiles\n");
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance(), 500);
|
||||
Sprite* sprite = writer.sprite();
|
||||
if (!sprite)
|
||||
@ -973,6 +977,7 @@ void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& act
|
||||
showRemapPal();
|
||||
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance(), 500);
|
||||
Sprite* sprite = writer.sprite();
|
||||
frame_t frame = writer.frame();
|
||||
@ -991,6 +996,7 @@ void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& act
|
||||
void ColorBar::setTransparentIndex(int index)
|
||||
{
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Sprite* sprite = writer.sprite();
|
||||
if (sprite &&
|
||||
@ -1079,6 +1085,7 @@ void ColorBar::onTilesViewClearTiles(const doc::PalettePicks& _picks)
|
||||
// selected tiles to remove.
|
||||
doc::PalettePicks picks = _picks;
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance(), 500);
|
||||
Sprite* sprite = writer.sprite();
|
||||
ASSERT(writer.layer()->isTilemap());
|
||||
@ -1109,6 +1116,7 @@ void ColorBar::onTilesViewResize(const int newSize)
|
||||
showRemapTiles();
|
||||
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance(), 500);
|
||||
Sprite* sprite = writer.sprite();
|
||||
ASSERT(writer.layer()->isTilemap());
|
||||
@ -1154,6 +1162,7 @@ void ColorBar::onTilesViewDragAndDrop(doc::Tileset* tileset,
|
||||
|
||||
try {
|
||||
Context* ctx = UIContext::instance();
|
||||
InlineCommandExecution inlineCmd(ctx);
|
||||
ContextWriter writer(ctx, 500);
|
||||
Tx tx(writer.context(), Strings::color_bar_drag_and_drop_tiles(), ModifyDocument);
|
||||
if (isCopy)
|
||||
@ -1620,6 +1629,7 @@ void ColorBar::onTimerTick()
|
||||
|
||||
// Redraw all editors
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Doc* document(writer.document());
|
||||
if (document != NULL)
|
||||
@ -1702,6 +1712,7 @@ void ColorBar::updateCurrentSpritePalette(const char* operationName)
|
||||
if (UIContext::instance()->activeDocument() &&
|
||||
UIContext::instance()->activeDocument()->sprite()) {
|
||||
try {
|
||||
InlineCommandExecution inlineCmd(UIContext::instance());
|
||||
ContextWriter writer(UIContext::instance());
|
||||
Doc* document(writer.document());
|
||||
Sprite* sprite(writer.sprite());
|
||||
|
Loading…
Reference in New Issue
Block a user