What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Getting NullReferenceException sometimes in Combat Routine

handnavi

Well-Known Member
Joined
Jan 15, 2010
Messages
2,489
Reaction score
59
Hi,

sometimes i get the following Error over and over:
Code:
[11:16:07:954] System.NullReferenceException: Object reference not set to an instance of an object.
   at HandnavisBearTank.Classname.Combat() in c:\Users\Stefan\Downloads\Honorbuddy_2.0.0.5104\CustomClasses\HandnavisBearTank\HandnavisBearTank.cs:line 244
   at Styx.Bot.CustomBots.CombatBot.<CreateCombatBehavior>b__1e(Object ret) in c:\Users\Stefan\Downloads\Honorbuddy_2.0.0.5104\Bots\CombatBot.cs:line 235

Line 244 is the following:
Code:
if (!Me.CurrentTarget.IsFriendly && Me.CurrentTarget != null && Me.CurrentTarget.IsAlive == true && add.Count == 1 && Me.Mounted == false) //BESERK TIME

add is a list, generated one line ahead:

Code:
add = detectAdds();

detectadds():
Code:
        //Credit to CodeNameGamma for detectAdds code
        private List<WoWUnit> add = new List<WoWUnit>();
                private List<WoWUnit> detectAdds()
        {
            List<WoWUnit> addList = ObjectManager.GetObjectsOfType<WoWUnit>(false).FindAll(unit =>
                        unit.Guid != Me.Guid &&
                        unit.Distance < 10.00 &&
                        (unit.IsTargetingMyPartyMember || unit.IsTargetingMyRaidMember || unit.IsTargetingMeOrPet) &&
                        !unit.IsFriendly &&
                        !unit.IsPet &&
                        !Styx.Logic.Blacklist.Contains(unit.Guid));


            return addList;
        }

Can you give me a hint whats wrong?
It often happens, if a target immediately gets out of range, or dies. Do i miss any checks?
 
Hi,

sometimes i get the following Error over and over:
Code:
[11:16:07:954] System.NullReferenceException: Object reference not set to an instance of an object.
   at HandnavisBearTank.Classname.Combat() in c:\Users\Stefan\Downloads\Honorbuddy_2.0.0.5104\CustomClasses\HandnavisBearTank\HandnavisBearTank.cs:line 244
   at Styx.Bot.CustomBots.CombatBot.<CreateCombatBehavior>b__1e(Object ret) in c:\Users\Stefan\Downloads\Honorbuddy_2.0.0.5104\Bots\CombatBot.cs:line 235

Line 244 is the following:
Code:
if (!Me.CurrentTarget.IsFriendly && Me.CurrentTarget != null && Me.CurrentTarget.IsAlive == true && add.Count == 1 && Me.Mounted == false) //BESERK TIME

add is a list, generated one line ahead:

Code:
add = detectAdds();

detectadds():
Code:
        //Credit to CodeNameGamma for detectAdds code
        private List<WoWUnit> add = new List<WoWUnit>();
                private List<WoWUnit> detectAdds()
        {
            List<WoWUnit> addList = ObjectManager.GetObjectsOfType<WoWUnit>(false).FindAll(unit =>
                        unit.Guid != Me.Guid &&
                        unit.Distance < 10.00 &&
                        (unit.IsTargetingMyPartyMember || unit.IsTargetingMyRaidMember || unit.IsTargetingMeOrPet) &&
                        !unit.IsFriendly &&
                        !unit.IsPet &&
                        !Styx.Logic.Blacklist.Contains(unit.Guid));


            return addList;
        }

Can you give me a hint whats wrong?
It often happens, if a target immediately gets out of range, or dies. Do i miss any checks?

have the null checks first. or else the whole statement is useless.
Code:
if ([B]Me.CurrentTarget !=  null && [/B]!Me.CurrentTarget.IsFriendly && Me.CurrentTarget.IsAlive == true &&[B] add.Count > 0[/B] && Me.Mounted == false) //BESERK TIME

the whole credit to me for that code, isn't how i use it and without the context its being used in there's no way to tell whats actually going on.

you can never squash out all null errors they happen since even if the check is passed the mob can run out of sight, or despawn before it gets a chance to execute so you'll code will never be 100% null proof, specially in pvp.
 
have the null checks first. or else the whole statement is useless.
Code:
if ([B]Me.CurrentTarget !=  null && [/B]!Me.CurrentTarget.IsFriendly && Me.CurrentTarget.IsAlive == true &&[B] add.Count > 0[/B] && Me.Mounted == false) //BESERK TIME

the whole credit to me for that code, isn't how i use it and without the context its being used in there's no way to tell whats actually going on.

you can never squash out all null errors they happen since even if the check is passed the mob can run out of sight, or despawn before it gets a chance to execute so you'll code will never be 100% null proof, specially in pvp.

Ah okay, thanks alot for helping me!
"add.count == 1" was right, thats how i need it. :-)
 
Back
Top