diff options
author | rubidium <rubidium@openttd.org> | 2008-07-29 21:45:30 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-07-29 21:45:30 +0000 |
commit | ef6e366c08fecae818512145d8ed37bcc9f3cb06 (patch) | |
tree | 12b2d34ac161c4c16fcf48de937f7a5d81a5a0e8 | |
parent | 814c91843acbd3c42eb85939e68efc56ee1f065d (diff) | |
download | openttd-ef6e366c08fecae818512145d8ed37bcc9f3cb06.tar.xz |
(svn r13869) -Fix [FS#2153] (r13674): in some cases the sprite cache could be filled with unremovable items.
-rw-r--r-- | src/spritecache.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 0c5e1748d..296744ab5 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -137,7 +137,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) file_pos = GetSpriteCache(SPR_IMG_QUERY)->file_pos; } - if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) { + if (real_sprite && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) { #ifdef WITH_PNG /* Try loading 32bpp graphics in case we are 32bpp output */ SpriteLoaderPNG sprite_loader; @@ -147,7 +147,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite); free(sprite.data); - sc->real_sprite = true; + sc->real_sprite = real_sprite; return sc->ptr; } @@ -173,13 +173,13 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id); warning_level = 6; if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?"); - return (void*)GetSprite(SPR_IMG_QUERY); + return (void*)GetRawSprite(SPR_IMG_QUERY, true); } byte *dest = (byte *)AllocSprite(num); sc->ptr = dest; - sc->real_sprite = false; + sc->real_sprite = real_sprite; FioReadBlock(dest, num); return sc->ptr; @@ -194,6 +194,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) * something ;) The image should really have been a data-stream * (so type = 0xFF basicly). */ if (id >= 4845 && id <= 4881) { + assert(real_sprite); uint height = FioReadByte(); uint width = FioReadWord(); Sprite *sprite; @@ -221,22 +222,23 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) } } - sc->real_sprite = false; + sc->real_sprite = real_sprite; return sc->ptr; } - sc->real_sprite = true; - if (!real_sprite) { static byte warning_level = 0; DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id); warning_level = 6; + return (void*)GetRawSprite(id, true); } SpriteLoaderGrf sprite_loader; SpriteLoader::Sprite sprite; + sc->real_sprite = real_sprite; + if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos)) return NULL; if (id == 142) sprite.height = 10; // Compensate for a TTD bug sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite); |