[ZScript] Invalid Sprite Number when setting sprite directly

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

Moderator: GZDoom Developers

[ZScript] Invalid Sprite Number when setting sprite directly

Postby Xaser » Tue Dec 06, 2016 8:25 pm

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
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

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

Postby Major Cooke » Tue Dec 06, 2016 9:21 pm

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
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

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

Postby Xaser » Tue Dec 06, 2016 10:40 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

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

Postby Major Cooke » Wed Dec 07, 2016 12:04 am

Just like voxeldef then. Alright. Good to know.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

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

Postby Graf Zahl » Wed Dec 07, 2016 3:19 am

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 Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

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

Postby Graf Zahl » Thu Dec 08, 2016 12:16 pm

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
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

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

Postby Xaser » Thu Dec 08, 2016 12:36 pm

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
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

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

Postby Graf Zahl » Thu Dec 08, 2016 12:39 pm

It returns -1 if it can't find a sprite name in the list.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

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

Postby Xaser » Thu Dec 08, 2016 12:43 pm

Welp, sure enough. I need to commit "4294967295" to memory at some point.
User avatar
Xaser
anarchivist
 
 
 
Joined: 20 Jul 2003

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

Postby Edward-san » Thu Dec 08, 2016 1:38 pm

Graf, this commit (related to this thread it seems) breaks compilation because of gl_InitModels not being defined anywhere. Accidental change?
Edward-san
Mathematics is the language with which God has written the universe. (Galilei)
 
Joined: 17 Oct 2009

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

Postby Graf Zahl » Thu Dec 08, 2016 2:06 pm

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
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

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

Postby Major Cooke » Tue May 09, 2017 7:32 am

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.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

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

Postby Graf Zahl » Tue May 09, 2017 10:37 am

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.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to On Hold Bugs

Who is online

Users browsing this forum: ltx71 [Bot] and 0 guests