mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Possible fix for crash on attempt to free sdl surface in worked thread
This commit is contained in:
@@ -93,7 +93,9 @@ SDLImageShared::SDLImageShared(const ImagePath & filename)
|
||||
|
||||
void SDLImageShared::scaledDraw(SDL_Surface * where, SDL_Palette * palette, const Point & scaleTo, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return;
|
||||
|
||||
@@ -154,7 +156,9 @@ void SDLImageShared::scaledDraw(SDL_Surface * where, SDL_Palette * palette, cons
|
||||
|
||||
void SDLImageShared::draw(SDL_Surface * where, SDL_Palette * palette, const Point & dest, const Rect * src, const ColorRGBA & colorMultiplier, uint8_t alpha, EImageBlitMode mode) const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return;
|
||||
|
||||
@@ -221,7 +225,9 @@ void SDLImageShared::optimizeSurface()
|
||||
|
||||
std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL_Palette * palette, EImageBlitMode mode) const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (factor <= 0)
|
||||
throw std::runtime_error("Unable to scale by integer value of " + std::to_string(factor));
|
||||
|
||||
@@ -274,7 +280,9 @@ bool SDLImageShared::isLoading() const
|
||||
|
||||
std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (palette && surf->format->palette)
|
||||
SDL_SetSurfacePalette(surf, palette);
|
||||
|
||||
@@ -310,7 +318,9 @@ void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palet
|
||||
directory.remove_filename();
|
||||
boost::filesystem::create_directories(directory);
|
||||
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return;
|
||||
|
||||
@@ -323,7 +333,9 @@ void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palet
|
||||
|
||||
bool SDLImageShared::isTransparent(const Point & coords) const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (surf)
|
||||
return CSDL_Ext::isTransparent(surf, coords.x - margins.x, coords.y - margins.y);
|
||||
else
|
||||
@@ -332,7 +344,9 @@ bool SDLImageShared::isTransparent(const Point & coords) const
|
||||
|
||||
Rect SDLImageShared::contentRect() const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
auto tmpMargins = margins;
|
||||
auto tmpSize = Point(surf->w, surf->h);
|
||||
return Rect(tmpMargins, tmpSize);
|
||||
@@ -340,7 +354,9 @@ Rect SDLImageShared::contentRect() const
|
||||
|
||||
const SDL_Palette * SDLImageShared::getPalette() const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return nullptr;
|
||||
return surf->format->palette;
|
||||
@@ -348,13 +364,17 @@ const SDL_Palette * SDLImageShared::getPalette() const
|
||||
|
||||
Point SDLImageShared::dimensions() const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
return fullSize;
|
||||
}
|
||||
|
||||
std::shared_ptr<const ISharedImage> SDLImageShared::horizontalFlip() const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return shared_from_this();
|
||||
|
||||
@@ -370,7 +390,9 @@ std::shared_ptr<const ISharedImage> SDLImageShared::horizontalFlip() const
|
||||
|
||||
std::shared_ptr<const ISharedImage> SDLImageShared::verticalFlip() const
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
if (!surf)
|
||||
return shared_from_this();
|
||||
|
||||
@@ -387,7 +409,9 @@ std::shared_ptr<const ISharedImage> SDLImageShared::verticalFlip() const
|
||||
// Keep the original palette, in order to do color switching operation
|
||||
void SDLImageShared::savePalette()
|
||||
{
|
||||
assert(upscalingInProgress == false);
|
||||
if(upscalingInProgress)
|
||||
throw std::runtime_error("Attempt to access images that is still being loaded!");
|
||||
|
||||
// For some images that don't have palette, skip this
|
||||
if(surf->format->palette == nullptr)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user