[BUG] ItemEquipVerifier ShouldBlockAbilityStart and ShouldStopActiveAbility throw NullReferenceException on synced Character

echtnice

Member
Hi,

I investigated a NullReferenceException being thrown in ItemEquipVerifier's ShouldBlockAbilityStart and ShouldStopActiveAbility.
The problem only occurs for synced Characters (the ones where CharacterLocomotion is disabled).

The Callstack leading to the error is like this

PunCharacter.OnAbilityActiveRPC()
UltimateCharacterLocomotion.TryStartAbility()
ItemEquipVerifier.ShouldBlockAbilityStart()
ItemEquipVerifier.ShouldStopActiveAbility()

In ShouldBlockAbilityStart / ShouldStopActiveAbility, m_StartingAbility is null because the ability is not "really running" on synced characters. It should be safe to just check if m_StartingAbility is null and return false to fix this problem like below or?

ItemEquipVerifier:231
Code:
        public override bool ShouldBlockAbilityStart(Ability startingAbility)
        {
            // GUNFU:HACK prevent null deref in multiplayer mode
            if (m_StartingAbility == null) {
                return false;
            }
            return m_StartingAbility.ShouldBlockAbilityStart(startingAbility) || m_StartingAbility.Index < startingAbility.Index;
        }

        /// <summary>
        /// Called when the current ability is attempting to start and another ability is active.
        /// Returns true or false depending on if the active ability should be stopped.
        /// </summary>
        /// <param name="activeAbility">The ability that is currently active.</param>
        /// <returns>True if the ability should be stopped.</returns>
        public override bool ShouldStopActiveAbility(Ability activeAbility)
        {
            if (m_StartingAbility == null) {
                return false;
            }
            return m_StartingAbility.ShouldStopActiveAbility(activeAbility) || m_StartingAbility.Index < activeAbility.Index;
        }

Thanks!
 

Justin

Administrator
Staff member
That does look like a safe change but I would have thought that I would have hit this by now. Are you able to reproduce it within the demo scene of a fresh project?
 

echtnice

Member
Hmm Yes that made me wondering too ... I noticed it with one of my custom abilities. Will take a closer look and let you know.
 

echtnice

Member
Ok it seems that the Pun Demo scene in my OpsiveDemo project is broken and i probably have to set up a new one sometime soon.

Regarding this error, i could also trigger it in my project with your Pistol in Slot0 and Slot1 empty and in your Jump ability uncheck Allow Equipped items Slot0 and Slot1. If you now jump, you should see the error. Maybe you can verify in the Demo scene? Thanks a lot!
 
Top