Fix crash creating/blitting a surface of empty bounds

This commit is contained in:
David Capello 2017-08-11 15:53:04 -03:00
parent 511a34116b
commit f470daa939
3 changed files with 14 additions and 12 deletions

View File

@ -26,19 +26,18 @@ SkinPart::~SkinPart()
void SkinPart::clear()
{
for (Bitmaps::iterator it = m_bitmaps.begin(), end = m_bitmaps.end();
it != end; ++it) {
ASSERT(*it != NULL);
(*it)->dispose();
*it = NULL;
for (auto& bitmap : m_bitmaps) {
if (bitmap) {
bitmap->dispose();
bitmap = nullptr;
}
}
}
void SkinPart::setBitmap(std::size_t index, she::Surface* bitmap)
{
if (index >= m_bitmaps.size())
m_bitmaps.resize(index+1, NULL);
m_bitmaps.resize(index+1, nullptr);
m_bitmaps[index] = bitmap;
}

View File

@ -39,7 +39,7 @@ namespace app {
void setSlicesBounds(const gfx::Rect& bounds);
she::Surface* bitmap(std::size_t index) const {
return (index < m_bitmaps.size() ? m_bitmaps[index]: NULL);
return (index < m_bitmaps.size() ? m_bitmaps[index]: nullptr);
}
she::Surface* bitmapNW() const { return bitmap(0); }

View File

@ -676,17 +676,20 @@ she::Surface* SkinTheme::sliceSheet(she::Surface* sur, const gfx::Rect& bounds)
if (sur && (sur->width() != bounds.w ||
sur->height() != bounds.h)) {
sur->dispose();
sur = NULL;
sur = nullptr;
}
if (!sur)
sur = she::instance()->createRgbaSurface(bounds.w, bounds.h);
if (!bounds.isEmpty()) {
if (!sur)
sur = she::instance()->createRgbaSurface(bounds.w, bounds.h);
{
she::SurfaceLock lockSrc(m_sheet);
she::SurfaceLock lockDst(sur);
m_sheet->blitTo(sur, bounds.x, bounds.y, 0, 0, bounds.w, bounds.h);
}
else {
ASSERT(!sur);
}
return sur;
}