From be0539cb436ab096ecade239bef00b065a013199 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 12 Jun 2007 09:40:50 +0000 Subject: (svn r10109) -Fix [FS#838]: some NewGRFs use the same (unused in the "current" climate) sprite IDs. Normally this gives some artefacts, but when one NewGRF expects it to be a sprite and another NewGRF overwrites it with a non-sprite nasty things happen (drawing a non-sprite crashes OTTD). --- src/spritecache.cpp | 20 +++++++++++++++++--- src/spritecache.h | 6 +++--- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 438becf72..4a43faf2a 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -118,7 +118,7 @@ bool SpriteExists(SpriteID id) void* AllocSprite(size_t); -static void* ReadSprite(SpriteCache *sc, SpriteID id) +static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) { uint32 file_pos = sc->file_pos; @@ -139,6 +139,14 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id) byte type = FioReadByte(); /* Type 0xFF indicates either a colormap or some other non-sprite info */ if (type == 0xFF) { + if (real_sprite) { + static byte warning_level = 0; + 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) error("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); + } + byte *dest = (byte *)AllocSprite(num); sc->ptr = dest; @@ -186,6 +194,12 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id) return sc->ptr; } + 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; + } + SpriteLoaderGrf sprite_loader; SpriteLoader::Sprite sprite; @@ -403,7 +417,7 @@ void* AllocSprite(size_t mem_req) } -const void *GetRawSprite(SpriteID sprite) +const void *GetRawSprite(SpriteID sprite, bool real_sprite) { SpriteCache *sc; void* p; @@ -418,7 +432,7 @@ const void *GetRawSprite(SpriteID sprite) p = sc->ptr; /* Load the sprite, if it is not loaded, yet */ - if (p == NULL) p = ReadSprite(sc, sprite); + if (p == NULL) p = ReadSprite(sc, sprite, real_sprite); return p; } diff --git a/src/spritecache.h b/src/spritecache.h index 8356d0ff6..1b351bb0a 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -15,17 +15,17 @@ struct Sprite { extern uint _sprite_cache_size; -const void *GetRawSprite(SpriteID sprite); +const void *GetRawSprite(SpriteID sprite, bool real_sprite); bool SpriteExists(SpriteID sprite); static inline const Sprite *GetSprite(SpriteID sprite) { - return (Sprite*)GetRawSprite(sprite); + return (Sprite*)GetRawSprite(sprite, true); } static inline const byte *GetNonSprite(SpriteID sprite) { - return (byte*)GetRawSprite(sprite); + return (byte*)GetRawSprite(sprite, false); } void GfxInitSpriteMem(); -- cgit v1.2.3-70-g09d2