Page 1 of 1

[ZScript] Invalid Sprite Number when setting sprite directly

PostPosted: Tue Dec 06, 2016 8:25 pm
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
(814 Bytes) Downloaded 75 times

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

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

PostPosted: Tue Dec 06, 2016 9:21 pm
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.

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

PostPosted: Tue Dec 06, 2016 10:40 pm
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.

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

PostPosted: Wed Dec 07, 2016 12:04 am
by Major Cooke
Just like voxeldef then. Alright. Good to know.

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

PostPosted: Wed Dec 07, 2016 3:19 am
by Graf Zahl
I have to check if adding new indices at runtime is feasible. It depends on how the initialization works.

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

PostPosted: Thu Dec 08, 2016 12:16 pm
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.

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

PostPosted: Thu Dec 08, 2016 12:36 pm
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?

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

PostPosted: Thu Dec 08, 2016 12:39 pm
by Graf Zahl
It returns -1 if it can't find a sprite name in the list.

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

PostPosted: Thu Dec 08, 2016 12:43 pm
by Xaser
Welp, sure enough. I need to commit "4294967295" to memory at some point.

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

PostPosted: Thu Dec 08, 2016 1:38 pm
by Edward-san
Graf, this commit (related to this thread it seems) breaks compilation because of gl_InitModels not being defined anywhere. Accidental change?

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

PostPosted: Thu Dec 08, 2016 2:06 pm
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.

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

PostPosted: Tue May 09, 2017 7:32 am
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 allExpand view
Dummy:
ZOMB ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;
ZOMC ABCDEFGHIJKLMNOPQRSTUVWXYZ 0;


That works well enough in the mean time, for anyone else who might be encountering this issue.

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

PostPosted: Tue May 09, 2017 10:37 am
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.