mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-16 04:13:50 +00:00
Fix issue 446 crash calling replace color in a sprite with no layers
- Fix access to a NULL pointer in ReplaceColorFilterWrapper - Fix typo in NoImageException - Do not allow to remove all layers in RemoveLayerCommand
This commit is contained in:
parent
1c324c9b14
commit
7550db81ba
@ -31,6 +31,7 @@
|
||||
#include "app/undo_transaction.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "ui/alert.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace app {
|
||||
@ -66,6 +67,7 @@ void RemoveLayerCommand::onExecute(Context* context)
|
||||
std::string layer_name;
|
||||
ContextWriter writer(context);
|
||||
Document* document(writer.document());
|
||||
Sprite* sprite(writer.sprite());
|
||||
Layer* layer(writer.layer());
|
||||
{
|
||||
UndoTransaction undoTransaction(writer.context(), "Remove Layer");
|
||||
@ -73,13 +75,21 @@ void RemoveLayerCommand::onExecute(Context* context)
|
||||
// TODO the range of selected layer should be in the DocumentLocation.
|
||||
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||
if (range.enabled()) {
|
||||
Sprite* sprite = writer.sprite();
|
||||
if (range.layers() == sprite->countLayers()) {
|
||||
ui::Alert::show("Error<<You cannot delete all layers.||&OK");
|
||||
return;
|
||||
}
|
||||
|
||||
for (LayerIndex layer = range.layerEnd(); layer >= range.layerBegin(); --layer) {
|
||||
document->getApi().removeLayer(sprite->indexToLayer(layer));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sprite->countLayers() == 1) {
|
||||
ui::Alert::show("Error<<You cannot delete the last layer.||&OK");
|
||||
return;
|
||||
}
|
||||
|
||||
layer_name = layer->name();
|
||||
document->getApi().removeLayer(layer);
|
||||
}
|
||||
|
@ -52,11 +52,13 @@ public:
|
||||
|
||||
void setFrom(const app::Color& from) {
|
||||
m_from = from;
|
||||
ReplaceColorFilter::setFrom(color_utils::color_for_layer(from, m_layer));
|
||||
if (m_layer)
|
||||
ReplaceColorFilter::setFrom(color_utils::color_for_layer(from, m_layer));
|
||||
}
|
||||
void setTo(const app::Color& to) {
|
||||
m_to = to;
|
||||
ReplaceColorFilter::setTo(color_utils::color_for_layer(to, m_layer));
|
||||
if (m_layer)
|
||||
ReplaceColorFilter::setTo(color_utils::color_for_layer(to, m_layer));
|
||||
}
|
||||
|
||||
app::Color getFrom() const { return m_from; }
|
||||
|
@ -57,7 +57,7 @@ namespace app {
|
||||
class NoImageException : public base::Exception {
|
||||
public:
|
||||
NoImageException() throw()
|
||||
: base::Exception("There are not an active image to apply the effect.\n"
|
||||
: base::Exception("There is not an active image to apply the effect.\n"
|
||||
"Please select a layer/cel with an image and try again.") { }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user