[ZScript] Invalid Sprite Number when setting sprite directly

These bugs do plan to be resolved, when they can be.

Moderator: GZDoom Developers

User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

[ZScript] Invalid Sprite Number when setting sprite directly

Post by Xaser »

Stumbled across some undefined behavior while tinkering with this idea. If you directly actor's sprite property in a function (via passing a sprite name to GetSpriteIndex) to any sprite that isn't used somewhere on an actor state, GetSpriteIndex returns junk. This results in "invalid sprite number" console spam in the software renderer and a crash in GL.

A rather silly test:
setSpriteError.pk3
Summon "GoodSprite" and you'll see a Doom Imp ball. Summon "BadSprite" and you'll see "R_ProjectSprite: invalid sprite number 4294967295" spammed to the console (or a good ol' crash). The only difference between the two actors are the parameters to GetSpriteIndex -- "BAL1" on the former and "BALX" (a custom sprite included in the pk3, used nowhere else) on the latter.

Possibly a [Don't do that], but let's find out. :P
You do not have the required permissions to view the files attached to this post.
User avatar
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Major Cooke »

I disagree about it being a don't do that deal. Just seems like the sprite's not being buffered properly.

I'm curious, if you add a simple unused state with all the BALX sprites that's never reached, does it continue throwing feces at your log like an angry chimp?

I ask this because Voxeldef bitches whenever you don't have a sprite to pair it up to. I'm thinking that could be the same thing, in a manner of speaking.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Xaser »

It works flawlessly if you have a BALX somewhere on some state (any actor, anywhere... so long as the wad's loaded of course :P ). Means this isn't a showstopper, fortunately, though crashes are no fun.
User avatar
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Major Cooke »

Just like voxeldef then. Alright. Good to know.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49096
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Graf Zahl »

I have to check if adding new indices at runtime is feasible. It depends on how the initialization works.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49096
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Graf Zahl »

Currently the sprite setup works by walking through the list of used sprites and then collecting all data for each. The entire algorithm is designed to do this once at game start, so in its current state it cannot retroactively add new sprite names at run time.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Xaser »

Underastandable. Is there (or could we have) a reliable way to check if GetSpriteIndex returns something valid so we can safeguard it in-script?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49096
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Graf Zahl »

It returns -1 if it can't find a sprite name in the list.
User avatar
Xaser
 
 
Posts: 10772
Joined: Sun Jul 20, 2003 12:15 pm

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Xaser »

Welp, sure enough. I need to commit "4294967295" to memory at some point.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Edward-san »

Graf, this commit (related to this thread it seems) breaks compilation because of gl_InitModels not being defined anywhere. Accidental change?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49096
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Graf Zahl »

Yes. I made the change in GZDoom but didn't realize that the file contained modifications before pushing directly to the ZDoom repo.
User avatar
Major Cooke
Posts: 8182
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Major Cooke »

Well the easiest way to combat this is to have a state where the actor never jumps to -- or a dummy actor -- which has all the sprites and frames, as Xaser and I discovered:

Code: Select all

Dummy:
ZOMB ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;
ZOMC ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;
That works well enough in the mean time, for anyone else who might be encountering this issue.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49096
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Invalid Sprite Number when setting sprite dire

Post by Graf Zahl »

You only need one state with the A frame. If a sprite gets referenced, all frames will be initialized, even if only one gets used.

Return to “On Hold Bugs”