Fix crash switching from a tilemap to a regular layer in tile mode & the preview window opened (fix #2854)

This commit is contained in:
David Capello 2021-08-19 20:31:23 -03:00
parent c46927dce6
commit 4e11d45769
2 changed files with 20 additions and 1 deletions

View File

@ -345,6 +345,17 @@ void Editor::setLayer(const Layer* layer)
oldGrid = getSite().grid();
m_observers.notifyBeforeLayerChanged(this);
// Remove extra cel information if we change between different layer
// type (e.g. from a tilemap layer to an image layer). This is
// useful to avoid a flickering effect in the preview window (using
// a non-updated extra cel to patch the new "layer" with the
// background of the previous selected "m_layer".
if ((layer == nullptr) ||
(m_layer != nullptr && m_layer->type() != layer->type())) {
m_document->setExtraCel(ExtraCelRef(nullptr));
}
m_layer = const_cast<Layer*>(layer);
m_observers.notifyAfterLayerChanged(this);

View File

@ -1021,7 +1021,15 @@ void Render::renderLayer(
m_extraImage &&
layer == m_currentLayer &&
((layer->isBackground() && render_background) ||
(!layer->isBackground() && render_transparent))) {
(!layer->isBackground() && render_transparent)) &&
// Don't use a tilemap extra cel (IMAGE_TILEMAP) in a
// non-tilemap layer (in the other hand tilemap layers allow
// extra cels of any kind). This fixes a crash on renderCel()
// when we were painting the Preview window using a tilemap
// extra image to patch a regular layer, when switching from a
// tilemap layer to a regular layer.
((layer->isTilemap()) ||
(!layer->isTilemap() && m_extraImage->pixelFormat() != IMAGE_TILEMAP))) {
if (frame == m_extraCel->frame() &&
frame == m_currentFrame) { // TODO this double check is not necessary
drawExtra = true;