Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Null bug with showInteractionDialog  (Read 2959 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Null bug with showInteractionDialog
« on: February 21, 2014, 01:29:48 PM »

I hit a null error with this code under certain conditions (namely, starting a new game, seeing the Newbie Guide dialog, then exiting without saving).  It's not something players run into, since they usually save pretty early, but I can consistently make the game crash with this.

It crashes on this line:  UI.showInteractionDialog(newbieGuide, blah);

Can't be reproduced in Vanilla, since there's nothing like that atm, and I suspect I've found an engine bug here, because I'm testing for any of those elements to return null, and they obviously aren't.

Relevant code section:

Code: java
            if (!Global.getSector().getPersistentData().containsKey(runThisOnce)) {
                Global.getSector().getPersistentData().put(runThisOnce, "false");
            }
            if(Global.getSector().getPersistentData().get(runThisOnce).equals("false")){
                Global.getSector().getPersistentData().put(runThisOnce,"true");
                CampaignUIAPI UI = Global.getSector().getCampaignUI();
                SectorEntityToken blah = Global.getSector().getCurrentLocation().createToken(0,0);
                if(blah != null && UI != null)
                {
                    InteractionDialogPlugin newbieGuide = new NewbieGuideDialogPlugin();
                    if(newbieGuide == null || blah == null || UI == null) return;
                    UI.showInteractionDialog(newbieGuide, blah);                   
                    //Sets up the player's ship in a way that doesn't suck too much.
                    CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
                    int currentCrew = cargo.getCrew(CargoAPI.CrewXPLevel.REGULAR);
                    cargo.removeCrew(CargoAPI.CrewXPLevel.REGULAR, currentCrew);
                    cargo.addCrew(CargoAPI.CrewXPLevel.REGULAR, (int) cargo.getMaxPersonnel() / 10 * 7  - 5);   
                    cargo.addMarines(5);   
                }   
            }
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #1 on: February 21, 2014, 02:07:19 PM »

Hmm. Stack trace?

It literally can't crash on on the line you're pointing to, btw, as long as UI != null - it'd have to be somewhere within that function. Which means it could be in the plugin, for example.


Btw: you can pass in null instead of blah. The standard dialog does nothing with it, it's just there so that the plugin can access the current interaction target using getInteractionTarget().
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #2 on: February 21, 2014, 03:31:52 PM »

Stack:

Spoiler
20719 [Thread-5] ERROR com.fs.starfarer.combat.O0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO  - java.lang.NullPointerException
java.lang.NullPointerException
   at com.fs.starfarer.ui.K.show(Unknown Source)
   at com.fs.starfarer.campaign.A.showInteractionDialog(Unknown Source)
   at data.scripts.world.systems.UniversalSpawnPoint.advance(UniversalSpawnPoint.java:138)
   at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
   at com.fs.starfarer.campaign.save.CampaignGameManager.o00000(Unknown Source)
   at com.fs.starfarer.campaign.save.CampaignGameManager.o00000(Unknown Source)
   at com.fs.starfarer.title.OoOO.o00000(Unknown Source)
   at com.fs.starfarer.title.D.actionPerformed(Unknown Source)
   at com.fs.starfarer.ui.O00oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.o00000(Unknown Source)
   at com.fs.starfarer.ui.F.processInput(Unknown Source)
   at com.fs.starfarer.ui.newsuper.super(Unknown Source)
   at com.fs.starfarer.B.ØÓÒ000(Unknown Source)
   at com.fs.oOOO.A.Ò00000(Unknown Source)
   at com.fs.starfarer.combat.O0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.o00000(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
[close]

UniversalSpawnPoint.advance(UniversalSpawnPoint.java:138  --> is the line I'm referring to.

I'll take a look at the plugin; maybe it's checking a state there that's leading to a crash, IDK how that could be, though, I don't think it touches anything outside itself or requires anything that could cause a null there.  Stranger things have happened though :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #3 on: February 21, 2014, 03:46:47 PM »

So this is the function it's actually crashing in:
at com.fs.starfarer.ui.K.show(Unknown Source)

Which is the show() function in the core Dialog class. Could you outline the exact sequence of events leading to the crash?

It might be triggered by calling showInteractionDialog() on the very first frame following a load; not everything in the UI might be initialized then (load calls engine.advance(0) right afterwards); something as simple as checking if (amount == 0) and then bailing out of your own advance() method might do the trick.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #4 on: February 21, 2014, 03:49:31 PM »

I'll try that out asap.  Doing some kewl shader stuff for work tonight so it'll take a little bit but I'll probably get you a test result tonight :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #5 on: February 21, 2014, 03:58:24 PM »

Sounds like fun!


Hope the advance() thing works; going to move this to modding too, since it's not an issue in vanilla (even though it's possibly being caused by some kind of issue in core).
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #6 on: February 22, 2014, 01:47:32 PM »

Took a look at this as soon as I could. 

You're right; delaying the operation by one frame keeps it from crashing when reloaded (although then the Newbie Guide fires again, but that's OK; if a user exits that fast for some strange reason, they probably need to see it again anyhow). 

Using a private boolean (waitMe) in the class that is initialized as true and gets set during Advance() like the code below prevents the crash.

Code: java
            if(waitMe){
                waitMe = false;
                return;
            }   
            if (!Global.getSector().getPersistentData().containsKey(runThisOnce)) {
                Global.getSector().getPersistentData().put(runThisOnce, "false");
            }
            if(Global.getSector().getPersistentData().get(runThisOnce).equals("false")){
                Global.getSector().getPersistentData().put(runThisOnce,"true");
                CampaignUIAPI UI = Global.getSector().getCampaignUI();
                SectorEntityToken blah = Global.getSector().getCurrentLocation().createToken(0,0);
                if(blah != null && UI != null)
                {
                    InteractionDialogPlugin newbieGuide = new NewbieGuideDialogPlugin();
                    if(newbieGuide == null || blah == null || UI == null) return;
                    UI.showInteractionDialog(newbieGuide, blah);                   
                    //Sets up the player's ship in a way that doesn't suck too much.
                    CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
                    int currentCrew = cargo.getCrew(CargoAPI.CrewXPLevel.REGULAR);
                    cargo.removeCrew(CargoAPI.CrewXPLevel.REGULAR, currentCrew);
                    cargo.addCrew(CargoAPI.CrewXPLevel.REGULAR, (int) cargo.getMaxPersonnel() / 10 * 7  - 5);   
                    cargo.addMarines(5);   
                }   
            }
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #7 on: February 22, 2014, 04:33:24 PM »

Hmm. Glad that fixed it; still not entirely sure why it'd crash in the first place though. I mean, I have a rough idea, but looking at the code, it doesn't quite add up. Am clearly missing something :) Have a feeling this is going to come up again.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Null bug with showInteractionDialog
« Reply #8 on: February 22, 2014, 08:53:44 PM »

I'll take a look at the Dialog when I can, but IIRC it's not talking to singletons or anything outside itself and it should be a new instance...

Hmm.

Maybe, on a reload like that (again, a really specific, edge-case situation) there's a one-frame hole where the player's FleetAPI isn't available?
Logged
Please check out my SS projects :)
Xeno's Mod Pack