ChrisNZL / Tallowmere2

Changelog, issue tracker, and development knowledge for Tallowmere 2.
https://tallowmere2.com
13 stars 0 forks source link

Null ref: T2.CreatureState.ReturnCreatureStateToPool #1004

Closed ChrisNZL closed 2 years ago

ChrisNZL commented 2 years ago

Auto report. 0.3.3. Feedback ID: 20220216-N9NQL

11:25:27, Frame 832236, LOG »  YouHaveDied: All player creatures have died.
11:25:27, Frame 832236, LOG »  Player 你爹 has fallen!

11:25:27, Frame 832236, LOG »  GameStruct.OnAllPlayersDied: All players have died.
Party died in room number: 16
Highest room number reached: 16

11:25:27, Frame 832236, LOG »  YouHaveDied: All player creatures have died.

11:25:27, Frame 832259, EXCEPTION »  NullReferenceException
>>>>> CRITICAL ERROR >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

T2.CreatureState.ReturnCreatureStateToPool ()
T2.LightningBoltGroup.SetState_WaitingToFadeOut ()
T2.LightningBoltGroup.CreateLightningBolt ()
T2.LightningBoltGroup.Update ()

GameStates: RompingThroughDungeon, GameOverScreen
OnlineGameInfo: Device is offline.
No previous server nor online game info.
GameSetupMode: CouchCoop
Players: 2
DungeonRoomTransitioner.state: Null
DungeonRoom.state: Ready
Room: 16 / 16
RoomModifiers: LightningOrbsOnly (全面通电), TankyMonsters (重装怪物), DoubleTrouble (双倍麻烦)
YouHaveDiedState: InitialDelay
SystemPlayer InputDevice: 键盘
HumanPlayer 1 InputDevice: XInput Controller
HumanPlayer 2 InputDevice: 键盘

Supposedly a null ref in this method, yet I can't find what else to check with my .Exists calls:

public void ReturnCreatureStateToPool () {
    this.enabled = false;

    if (creature.Exists()) {
        List<CreatureState> stateStack = creature._stateStack;
        if (stateStack.Exists()) {
            stateStack.Remove(this);
        }

        if (incapacitatesCreature && creature.Exists()) {
            List<CreatureState> incapacitatedStack = creature.incapacitatedStateStack;
            if (incapacitatedStack.Exists()) {
                incapacitatedStack.Remove(this);
                if (incapacitatedStack.Count <= 0) {
                    CreatureBody body = creature.Body;
                    if (body.Exists()) {
                        NeckRotator neckRotator = body.neckRotator;
                        if (neckRotator.Exists() && !neckRotator.enabled) {
                            neckRotator.MakeNeckLookStraight();
                        }
                    }
                }
            }
        }
    }

    if (lightningBoltGroup.Exists()) {
        lightningBoltGroup.instantiatedCreatureState = null;
        lightningBoltGroup = null;
    }

    OnReturnedToPool();

    if (creature.Exists()) {
        creature.OnStateStackChanged();
        creature = null;
    }

    #if UNITY_EDITOR
        // Catching some dumb Editor-only OnDisable thing where you can't set a transform when deactivating the parent
        try {
            transform.parent = pool.transform;
        }
        catch (System.Exception) { }

    #else
        if (transform.Exists() && pool.Exists()) {
            Transform poolTransform = pool.transform;
            if (poolTransform.Exists()) {
                transform.parent = poolTransform;
            }
        }

    #endif

    if (pool.Exists()) {
        List<CreatureState> availableCopies = pool.availableCopies;
        if (availableCopies.Exists() && !availableCopies.Contains(this)) {
            availableCopies.Add(this);
        }
    }
}

Stack trace, was calling

instantiatedCreatureState?.ReturnCreatureStateToPool();

... have changed that now to:

if (instantiatedCreatureState.Exists()) {
    instantiatedCreatureState.ReturnCreatureStateToPool();
}
ChrisNZL commented 2 years ago

So, hopefully fixed in 0.3.4 by adjusting the call with a better .Exists check.