PSprites with an ID of 0 can be created infinitely

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!

PSprites with an ID of 0 can be created infinitely

Postby Boondorl » Mon Jan 10, 2022 2:41 pm

As the title suggests, there's currently an oversight with PSprites that are assigned an ID of 0. While PSprites with that ID can be created freely via GetPSprite(), the issue arises with FindPSprite(). If an argument of 0 is passed it will always return null. This forces GetPSprite() to create a new PSprite every time. Normally PSprites do a duplicate check on creation to make sure copies aren't created, but this check is specifically ignored if the ID is 0. This means any time GetPSprite() with an argument of 0 is called, a new PSprite will be created. This can be verified in-game:

Code: Select allExpand view
class CustomActor : Actor
{
    override void PostBeginPlay()
    {
        super.PostBeginPlay();

        players[consoleplayer].GetPSprite(0);
        players[consoleplayer].GetPSprite(0);
        players[consoleplayer].GetPSprite(0);
        players[consoleplayer].GetPSprite(0);
        players[consoleplayer].GetPSprite(0);

        let psp = players[consoleplayer].psprites;
        while (psp)
        {
            if (psp.id == 0)
            {
                console.printf("PSprite with id 0 exists");
                if (!players[consoleplayer].FindPSprite(0))
                    console.printf("Cannot find layer 0 despite existing");
            }

            psp = psp.next;
        }
    }
}

Summon the actor via the console and this code will print 5 times. Tested on the latest GZDoom build (4.7.1).
User avatar
Boondorl
 
Joined: 11 Jul 2018

Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests