[ZScript] Invalid Sprite Number when setting sprite directly
Moderator: GZDoom Developers
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
[ZScript] Invalid Sprite Number when setting sprite directly
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: 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.
A rather silly test: 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.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 8193
- 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
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.
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.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: [ZScript] Invalid Sprite Number when setting sprite dire
It works flawlessly if you have a BALX somewhere on some state (any actor, anywhere... so long as the wad's loaded of course ). Means this isn't a showstopper, fortunately, though crashes are no fun.
-
- Posts: 8193
- 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
Just like voxeldef then. Alright. Good to know.
-
- Lead GZDoom+Raze Developer
- Posts: 49143
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Invalid Sprite Number when setting sprite dire
I have to check if adding new indices at runtime is feasible. It depends on how the initialization works.
-
- Lead GZDoom+Raze Developer
- Posts: 49143
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Invalid Sprite Number when setting sprite dire
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.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: [ZScript] Invalid Sprite Number when setting sprite dire
Underastandable. Is there (or could we have) a reliable way to check if GetSpriteIndex returns something valid so we can safeguard it in-script?
-
- Lead GZDoom+Raze Developer
- Posts: 49143
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Invalid Sprite Number when setting sprite dire
It returns -1 if it can't find a sprite name in the list.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
Re: [ZScript] Invalid Sprite Number when setting sprite dire
Welp, sure enough. I need to commit "4294967295" to memory at some point.
-
- Posts: 1774
- Joined: Sat Oct 17, 2009 9:40 am
Re: [ZScript] Invalid Sprite Number when setting sprite dire
Graf, this commit (related to this thread it seems) breaks compilation because of gl_InitModels not being defined anywhere. Accidental change?
-
- Lead GZDoom+Raze Developer
- Posts: 49143
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Invalid Sprite Number when setting sprite dire
Yes. I made the change in GZDoom but didn't realize that the file contained modifications before pushing directly to the ZDoom repo.
-
- Posts: 8193
- 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
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:
That works well enough in the mean time, for anyone else who might be encountering this issue.
Code: Select all
Dummy:
ZOMB ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;
ZOMC ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;
-
- Lead GZDoom+Raze Developer
- Posts: 49143
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Invalid Sprite Number when setting sprite dire
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.