Skip to content

P_SpawnGhostMobj() - Potential Logical Error

In the file src/p_user.c a method is defined named P_SpawnGhostMobj() responsible, amongst other things, for producing the cloned ghostly mobj_t that follows a player sometimes during gameplay as a visual effect.

The method is designed to deep-copy a large amount of one mobj_t into another then adjust the result from there to make the latter of the two mobj_t instances appear as a ghost. Below is a snippet example of how that is achieved throughout the implementation:

	ghost->spritexscale = mobj->spritexscale;
	ghost->spriteyscale = mobj->spriteyscale;
	ghost->spritexoffset = mobj->spritexoffset;
	ghost->spriteyoffset = mobj->spriteyoffset;

	if (mobj->flags2 & MF2_OBJECTFLIP)
		ghost->flags |= MF2_OBJECTFLIP;

	if (!(mobj->flags & MF_DONTENCOREMAP))
		ghost->flags &= ~MF_DONTENCOREMAP;

Most of this makes sense to me however the subject of this issue is this part in particular:

	if (mobj->flags2 & MF2_OBJECTFLIP)
		ghost->flags |= MF2_OBJECTFLIP;

It's doesn't make sense to me from both observation of the rest of the source code and my understanding of bitwise operations to interact MF2_ flag values with an MF_ member like flags. Additionally, the member name that MF2_ flags are intended to interact with, flags2, is only one character removed from the flags member. What I am suggesting is that ghost->flags is likely a typo and that the snippet above should instead read as the following:

	if (mobj->flags2 & MF2_OBJECTFLIP)
		ghost->flags2 |= MF2_OBJECTFLIP;

I cannot (be bothered to) contrive a situation in-game in which this typo theory could be proven and I do not want to make a merge request resolving this "issue" until I can have it confirmed by the developers that my theory is correct, not to mention that it's such a tiny change that a merge request would be far slower than a member of the team themselves resolving this. Given all this, I put this issue ticket out to you the dev team to see what you think. Is it a typo? Is it intentional? Whatever the case, I feel glad to have made sure the occurrence went noticed.