Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2012, 11:23 PM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default Null exception

@ kodiak or others who could ponder an issue.

We have been noticing after a mission is running for a while(it isnt consistant) we see a null exception error

System.NullReferenceException: Object reference not set to an instance of an object. at(blah blah CLOD code references)

I've been pondering if the reference is actually objects or lists of objects as Ai aircraft that are destroyed through despawner type methods. However the list reference is not completely cleared or purged from the system operating memory. Or if you have dual conditions to call a despawner, say at the completion of a path and time period, whre the object completes the path, the timer reference carries on and looks for the object when times up, and when the object does not exsist anymore and thus the exception.

The question is, is what I discribe a possibility, then if so, how do we purge the references. I was wondering if despawners should despawn the mission number they spawn in on.

Last edited by Smokeynz; 03-13-2012 at 05:56 AM.
Reply With Quote
  #2  
Old 03-13-2012, 04:23 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

if you have a list for example:

List<AiAircraft> PlaneList = new List<AiAircraft>();

PlaneList.Add(aircraft1); // only examples
PlaneList.Add(aircraft2);


aircraft2.Destroy();

So now we have the aircraft2 already in List. Maybe more of destroyed Aircrafts. To remove them from List:
PlaneList.RemoveAll(item => item == null); // removes all null valued Aircrafts from list.
Reply With Quote
  #3  
Old 03-13-2012, 08:10 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

Ok I can confirm after testing it is a double up on one object, being an Aiaircraft
The problem is because I have applied two options for despawning aiaircraft,
one is via Ontaskcompleted or final path point, then I run
Timeout(despawntime2, () => { damageAiControlledPlane(actor); });

However I also run OnActorcreated upon the same object
Timeout(despawntime, () => { damageAiControlledPlane(actor); });

So hence I am trying to run the despawner upon the same object twice, in early testing the nullpointer exception did not show up, which is kinda random reaction.

The theory for why I use time periods is to allow aiplane use for players, but also I want to despawn for short flight path aiaircraft, since the timer period is 45~60 minutes.

So choice is, rely on one timer or somehow purge the remaining object timer
Usually the problem is overall timer as this is longer, but either can also overlap.

Kodiak I see how to reference a list object by null, but how to reference this aiaircraft as it is the timer acting upon the ai aircraft.

Code:


 #region Despawner  

    /*
    despawner timer added to original code, sets overall time period for actors,
    Advantage is, if delayed, say trying to land behind masses of planes, actors despawn at timer period set anyway.
    allows for players to fly groups of planes, 
    Player can re eneter flights or groups, as bombers take them to target, use each at target then fly group home
    despawn only triggers once player leaves whole group
*/
    public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorCreated(missionNumber, shortName, actor);

        // note despawntime (set as varible at start of cs) 
        if (actor is AiGroundActor && missionNumber > 0)//main mission is left alone
            //if ((actor as AiGroundActor).Type() != maddox.game.world.AiGroundActorType.AAGun)//all ai ground except aa guns
            Timeout(despawntime3, () =>
            {
                if (actor != null)
                { (actor as AiGroundActor).Destroy(); }
            });

        if (actor is AiAircraft)        
            Timeout(despawntime, () => { damageAiControlledPlane(actor); });     
    }
 
    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);
        Timeout(despawntime, () => { damageAiControlledPlane(actor); });        
    }
    
    // Path completion despawner, when flight path ends despawner action triggered
    // note:final despawner detects players in group    

    public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);
        if (actor is AiGroundActor) 
            if (actor != null)
                Timeout(despawntime2, () => { (actor as AiGroundActor).Destroy(); });
            
        Timeout(despawntime2, () => { damageAiControlledPlane(actor); });
    }

    //check if a player is in any of the "places"
    private bool isAiControlledPlane(AiAircraft aircraft)
    {
        if (aircraft == null) return false;        
        for (int i = 0; i < aircraft.Places(); i++)
            if (aircraft.Player(i) != null)
                return false;
        return true;
    }

    private void destroyPlane(AiAircraft aircraft)
    {
        if (aircraft != null)
            aircraft.Destroy();
    }

    //actual Aiaircraft despawner, note it polls player detection
    private void damageAiControlledPlane(AiActor actorMain)
    {        
        foreach (AiActor actor in actorMain.Group().GetItems())
        {
            if (actor == null || !(actor is AiAircraft))
                return;
            AiAircraft aircraft = (actor as AiAircraft);
            if (!isAiControlledPlane(aircraft))
                return;
            if (aircraft == null)
                return;
            (actor as AiAircraft).Destroy();             
        }
    }

    #endregion

    /*=========================================*/
Reply With Quote
  #4  
Old 03-13-2012, 08:46 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

For me it seems the error is in
Code:
 private void damageAiControlledPlane(AiActor actorMain)
    {        
        foreach (AiActor actor in actorMain.Group().GetItems())
        {
            if (actor == null || !(actor is AiAircraft))
                return;
            AiAircraft aircraft = (actor as AiAircraft);
            if (!isAiControlledPlane(aircraft))
                return;
            if (aircraft == null)
                return;
            (actor as AiAircraft).Destroy();             
        }
    }
Why you use the Group to destroy a single Airplane? Do you test the Group for null value? It make no sense to me to use the Group in this case.
Reply With Quote
  #5  
Old 03-13-2012, 09:24 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

hmmm that bit is straight from collection, despawner, unmodified.

Thought it was trying to handle group of planes, works without me applying several attemps to run this, as single routine ok, with double up it seems cause error.
Reply With Quote
  #6  
Old 03-13-2012, 05:09 PM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

IIRC group must be used in case a player creates e.g. 6 bombers, then leaves his aircraft to create another group of 5 bombers, etc., etc. If each aircraft in a group is not removed this would lead to AI spamming. Groups and foreach cycle is the solution to this IIRC.
Reply With Quote
  #7  
Old 03-13-2012, 05:39 PM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

cheers Ataros, Yep thats how I understood it

For the moment I decided to run just one Triggered despawn timer from the On created.

Actually I wonder if the despawning routine justs needs a catch for null, timers completing looking for aircraft to despawn that have been destroyed already, or despawned already.
Im sure in the case of aircraft destroyed we see the same nullpoint exception looking for the aircraftat a later time.
Also be nice to purge references of aircraft from the oncreated that dont exist anymore(this happens with despawner, but maybe not by ingame shot down destroyed)

Last edited by Smokeynz; 03-13-2012 at 05:45 PM.
Reply With Quote
  #8  
Old 03-14-2012, 04:19 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

No the group is not nessesary, every Actor you created calls OnActorCreated(..) so every Actor is destroyed after the amount of time.
It's doppelt gemoppelt as we germans says .
And there is no test if the group exists.
if(actorMain.Group() != null)
Reply With Quote
  #9  
Old 03-14-2012, 06:49 AM
Smokeynz Smokeynz is offline
Approved Member
 
Join Date: Apr 2011
Posts: 106
Default

So I presume this trimmed version is all that is needed

NOTE this edit cause another error...sigh
Code:
private void damageAiControlledPlane(AiActor actorMain)
    {        
         if (actor == null || !(actor is AiAircraft))
              return;
         AiAircraft aircraft = (actor as AiAircraft);
         if (!isAiControlledPlane(aircraft))
              return;
         if (aircraft == null)
              return;
         (actor as AiAircraft).Destroy();             
     }

Last edited by Smokeynz; 03-14-2012 at 07:27 AM.
Reply With Quote
  #10  
Old 03-14-2012, 07:30 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Why so complicated

Code:
 private void damageAiControlledPlane(AiActor actorMain)
    {
        if (actorMain != null && actorMain is AiAircraft)
            if (isAiControlledPlane(actorMain as AiAircraft))
                    (actorMain as AiAircraft).Destroy();
    }
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.