BUG: Game.SpriteHeight/Width returns 1 for non-existent sprites

Started by monkey0506, Fri 21/08/2009 08:08:20

Previous topic - Next topic

monkey0506

I was just playing around with an idea to try and validate sprite numbers being passed into my functions when I thought, "I know, I'll check the SpriteHeight and SpriteWidth!" The problem is that Game.SpriteHeight and Game.SpriteWidth return 1 for a non-existent sprite. This makes it impossible to distinguish between a non-existent sprite and a 1x1 pixel sprite.

So I thought, perhaps I can see if I can generate a null DynamicSprite...no, if I pass an invalid sprite slot to that function the game crashes.

The biggest thing I was curious about was why these properties return 1 for non-existent sprites instead of the more logical 0? If the user is passing invalid sprite slots that's their problem anyway (:P) I was just trying to see what options I had to check for the existence of a specific sprite slot...which is apparently none except crashing the game means it's not there. ::)

Edit: I've updated this to "bug" status because I have yet to see any further information on it...? :-\

Gilbert

In fact, from the manual entries of Game.SpriteWidth[] and Game.SpriteHeight[] we have:
Quote
If an invalid sprite slot is supplied, 0 will be returned.

I have not tested it myself, but if you get an 1 from a non-existing sprite I think it's a bug (this answers the 'why' in your last paragraph I think) in the engine.

monkey0506

Well the code I had (AGS 3.2 BETA 4) is this:

Code: ags
function game_start() {
  Display("width: %d, height: %d", Game.SpriteWidth[4], Game.SpriteHeight[4]);
  DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(4); // crash
  if (sprite == null) Display("Sprite does not exist.");
}


The display I get is "width: 1, height: 1" no matter how many different invalid sprite slots I specify. I tried right clicking on the number four and "Go to sprite 4" but it says it can't be found. And then of course the game crashes trying to create the DynamicSprite.

So I guess that this would be a bug then. Not sure what versions it might apply to, but as I said I have this issue with the latest beta.

Pumaman

Well spotted, the behaviour here doesn't match the documentation. What's actually happening is it's returning the size of Sprite 0 (the Blue Cup) since that is what will be displayed for any invalid sprites.

I'll get it fixed to return 0.

SMF spam blocked by CleanTalk