Fix crash using a deleted surface in Overlay::restoreOverlappedArea()

Can happen when a resize event is received and m_captured stores the
surface with the old window size.

This was found opening a file from the CLI on Linux/X11.
This commit is contained in:
David Capello 2022-06-14 21:38:47 -03:00
parent e2798bc849
commit c58dae51fa
3 changed files with 9 additions and 9 deletions

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -83,7 +83,7 @@ void Overlay::moveOverlay(const gfx::Point& newPos)
m_pos = newPos;
}
void Overlay::captureOverlappedArea(os::Surface* screen)
void Overlay::captureOverlappedArea(const os::SurfaceRef& screen)
{
if (!m_surface ||
m_captured)
@ -116,7 +116,7 @@ void Overlay::restoreOverlappedArea(const gfx::Rect& restoreBounds)
return;
os::SurfaceLock lock(m_overlap.get());
m_overlap->blitTo(m_captured, 0, 0, m_pos.x, m_pos.y,
m_overlap->blitTo(m_captured.get(), 0, 0, m_pos.x, m_pos.y,
m_overlap->width(), m_overlap->height());
Manager::getDefault()->dirtyRect(bounds());

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -41,7 +41,7 @@ namespace ui {
const gfx::Point& position() const { return m_pos; }
gfx::Rect bounds() const;
void captureOverlappedArea(os::Surface* screen);
void captureOverlappedArea(const os::SurfaceRef& screen);
void restoreOverlappedArea(const gfx::Rect& restoreBounds);
void drawOverlay();
@ -57,7 +57,7 @@ namespace ui {
// Surface where we captured the overlapped (m_overlap)
// region. It's nullptr if the overlay wasn't drawn yet.
os::Surface* m_captured;
os::SurfaceRef m_captured;
gfx::Point m_pos;
ZOrder m_zorder;

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2018-2022 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
@ -86,8 +86,8 @@ void OverlayManager::drawOverlays()
if (!manager)
return;
os::Surface* displaySurface = manager->display()->surface();
os::SurfaceLock lock(displaySurface);
os::SurfaceRef displaySurface(base::AddRef(manager->display()->surface()));
os::SurfaceLock lock(displaySurface.get());
for (auto& overlay : *this)
overlay->captureOverlappedArea(displaySurface);