• Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • SpellManager.CanCast() bugging out within Behavior Trees

    Discussion in 'Honorbuddy Support' started by strix, Sep 26, 2011.

    1. strix

      strix New Member

      Joined:
      Feb 13, 2010
      Messages:
      442
      Likes Received:
      18
      Trophy Points:
      0
      SpellManager.CanCast() (and almost every single Lua call) is very often throwing errors like this in a loop when called within Behavior Tree, quickly filling megabytes of logs:
      Code:
      [3:11:33 PM:464] System.NullReferenceException: Object reference not set to an instance of an object.
       at Apsalar.ApsalarRoutine.<CreateMovement>b__11(Objec t ret) in c:\Users\woodrow\Documents\papa\CustomClasses\Apsa lar\Apsalar.Combat.cs:line 93
       at TreeSharp.Decorator.CanRun(Object context)
       at TreeSharp.Decorator.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.Decorator.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.Decorator.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.Decorator.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.Decorator.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at TreeSharp.PrioritySelector.#h.#nF.MoveNext()
       at (Object )
       at TreeSharp.Composite.Tick(Object context)
       at Styx.Logic.BehaviorTree.TreeRoot.Tick()
       [3:11:33 PM:464] Cleared POI - Reason Exception in Root.Tick()
       [3:11:33 PM:464] Cleared POI
      At least in my CC it's doing that. Any ideas?
       
    2. Gilderoy

      Gilderoy New Member

      Joined:
      May 10, 2010
      Messages:
      761
      Likes Received:
      16
      Trophy Points:
      0
      if I'm not wrong this is your line that is giving the error
      CreateCast("Sprint", ret => !Settings.DisableMovementAndTargeting && Me.CurrentTarget.Distance > 8 && (!SpellManager.CanCast("Shadowstep") || Settings.DisableMovementAndTargeting)),
      Am I right?
      Couse if that is the case I see a major issue in your code, and is not in the can cast the problem
      You cannot call Me.CurrentTarget.Distance if you do not have before checked for Me.CurrentTarget!=null and Me.CurrentTarget.IsValid
      That because if you do anytime you have no target the CC will give that error :)
      try to change your line to
      CreateCast("Sprint", ret => !Settings.DisableMovementAndTargeting && Me.CurrentTarget!=null && Me.CurrentTarget.IsValid && Me.CurrentTarget.Distance > 8 && (!SpellManager.CanCast("Shadowstep") || Settings.DisableMovementAndTargeting)),
      And see if this FIX your problem :)
      OFC has to be done for every line where you have a Me.CurrentTarget.(whatever) call..
       
    3. CodenameG

      CodenameG New Member

      Joined:
      Jan 15, 2010
      Messages:
      38,369
      Likes Received:
      231
      Trophy Points:
      0
      well what is before and after line 93?

      if its only happening once an enemy is dead, then its nothing to worry about, but if its spamming it, then theres something else thats returning null thats not suppose to be, and no, chances are its not getting it from Spellmanager.CanCast().
       
    4. strix

      strix New Member

      Joined:
      Feb 13, 2010
      Messages:
      442
      Likes Received:
      18
      Trophy Points:
      0
      It's looping errors whenever i try to get Lua return values and in CreateCast():
      Code:
              private Composite CreateCast(string spellName, CanRunDecoratorDelegate extraRun)
              {
                  return new Decorator(extraRun,
                      new Decorator(
                          ret => SpellManager.HasSpell(spellName) && 
                              SpellManager.CanCast(spellName) && 
                              Me.CurrentTarget.InLineOfSight &&
                              SpellManager.Cast(spellName),
                          new ActionLog("Casted " + spellName + ".")));
              }
       
    5. raphus

      raphus Administrator Staff Member Moderator Buddy Core Dev

      Joined:
      Jun 17, 2010
      Messages:
      2,094
      Likes Received:
      492
      Trophy Points:
      83
      Either have a Me.CurrentTarget != null check at top or before every Me.CurrentTarget property/field/method you use

      Code:
              
             private Composite CreateCast(string spellName, CanRunDecoratorDelegate extraRun)
              {
                  return new Decorator(extraRun,
                      new Decorator(
                          ret => SpellManager.HasSpell(spellName) && 
                              SpellManager.CanCast(spellName) && 
                              Me.CurrentTarget != null &&
                              Me.CurrentTarget.InLineOfSight &&
                              SpellManager.Cast(spellName),
                          new ActionLog("Casted " + spellName + ".")));
              }
       
    6. Gilderoy

      Gilderoy New Member

      Joined:
      May 10, 2010
      Messages:
      761
      Likes Received:
      16
      Trophy Points:
      0
      again couse you are using Me.CurrentTarget.InLineOfSight without checking for the existance of Me.CurrentTarget..
       

    Share This Page