Lights attached to inventory items are not attached in a new level

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Lights attached to inventory items are not attached in a new level

Post by Sir Robin »

Issue: If you have an inventory item with an attached light, that light is no longer attached after changing levels.

Sample code:

Code: Select all

//GLDEFS
pointlight GreenLight {
	color 0.25 1.0 0.25
	size 128
}

//ZSCRIPT
version "4.10.0"

class GreenLight : inventory
{
	Default
	{
		Radius 20;
		Height 14;
		ProjectilePassHeight -16;
	}
		
	States
	{
		Spawn:
		Held:
			CAND A -1 Bright Light("GreenLight");
			CEYE ABCB 6 Bright Light("GreenLight");
			Loop;
	}
	
	override void tick()
	{
		Super.tick();
		
		//Keep item in owner eyesight
		if (owner && owner.player)
		{
			vector3 newPos = owner.pos + (0,0,owner.player.viewheight);
			if (pos != newPos) SetOrigin(newPos,true);
		}
	}
}
Reproduce: give the GreenLight, notice the green light, go to exit, on next level notice no green light although the item is still in inventory

Also, comment the CAND line so that the CEYE animation plays. Now it works as expected. Seems this is only an issue for infinite state sprites.

workaround: resetting the state seems to fix it.

Code: Select all

	override void travelled()
	{
		setstate(ResolveState("Spawn"));
	}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49118
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Lights attached to inventory items are not attached in a new level

Post by Graf Zahl »

The real bug here is that the item still emits light when in the inventory. Messing around with the 'Held' state like this is entirely undefined behavior.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Lights attached to inventory items are not attached in a new level

Post by Sir Robin »

I think you're saying that the bug is that an actor in NoSector mode shouldn't have it's attached lights rendered at all
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49118
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Lights attached to inventory items are not attached in a new level

Post by Graf Zahl »

No, the bug is that an owned inventory item, i.e. something that isn't physically in the map, can emit light.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Lights attached to inventory items are not attached in a new level

Post by Sir Robin »

I think we're saying the same thing. When an inventory object is taken into inventory, it is given the NoBlockMap status to prevent collisions and the NoSector status to prevent it from being drawn out in the world. So whatever internal routine handles that light attachment should check for NoSector mode and fail if true.

That's the same as what you're saying:
No item not in the world, e.g. in inventory, i.e. in NoBlockMap and NoSector modes, should be able to emit light out into the world.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49118
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Lights attached to inventory items are not attached in a new level

Post by Graf Zahl »

No, that's not what I mean. These flags make the actor invisible but they are still interacting with the map. An owned item does not interact with the map.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Lights attached to inventory items are not attached in a new level

Post by Sir Robin »

Ok, so this statement is still true:
No item not in the world, e.g. in inventory, should be able to emit light out into the world.
But you disagree that NoBlockMap and NoSector would be the indicators of such condition.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: Lights attached to inventory items are not attached in a new level

Post by Sir Robin »

You probably know way more about the code than I do, but I still think NoSector is the best indicator of an actor that shouldn't interact with the map. There is NoInteraction, but that seems to indicate that the actor shouldn't be interacted with, not that it doesn't interact. The Inventory.BecomeItem() method shows what changes when the item leaves the world to enter inventory mode:

Code: Select all

	void BecomeItem ()
	{
		if (!bNoBlockmap || !bNoSector)
		{
			A_ChangeLinkFlags(1, 1);
		}
		ChangeTid(0);
		bSpecial = false;
		// if the item was turned into a monster through Dehacked, undo that here.
		bCountkill = false;
		bIsMonster = false;
		ChangeStatNum(STAT_INVENTORY);
		// stop all sounds this item is playing.
		A_StopAllSounds();
		SetState (FindState("Held"));
	}
The most significant change is the link flags

And in the GoAwayAndDie() method:

Code: Select all

	protected void GoAwayAndDie ()
	{
		if (!GoAway ())
		{
			bSpecial = false;
			if (!bNoBlockmap || !bNoSector)	// make sure that the item no longer interacts with the world for the short rest of its life.
			{
				A_ChangeLinkFlags(1, 1);
			}
			SetStateLabel("HoldAndDestroy");
		}
	}
The comment indicates that the best way to signal an actor shouldn't interact is thru the link flags.

In my own code I've been using if (!owner) to tell if the actor should be interacting with the environment or not

But I'm just reporting the behavior as noted. If the bug is fixed or not is up to someone else. As stated I've also got the workaround. Do with this information as you will.
Professor Hastig
Posts: 246
Joined: Mon Jan 09, 2023 2:02 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Lights attached to inventory items are not attached in a new level

Post by Professor Hastig »

What something 'should' do is often not what things do. NOSECTOR is often being used to create invisible actors, like the teleport destination. I think the placeable dynamic light actor also uses this flag.
So based on the flag alone you cannot assume anything. In this particular case the important info to look for is not the actor's flags but its ownership state.

Return to “Bugs [GZDoom]”