Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Weird Null Pointer crash  (Read 4586 times)

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Weird Null Pointer crash
« on: December 27, 2015, 09:45:05 AM »

Hi MShadowy,

Some weeks ago i mentioned a CTD while fighting with or/and against SRA ships.
The log only showing this:

Quote
501901 [Thread-5] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException
java.lang.NullPointerException
   at com.fs.starfarer.combat.entities.ship.null.String(Unknown Source)
   at com.fs.starfarer.combat.entities.ship.null.advance(Unknown Source)
   at com.fs.starfarer.combat.entities.Ship.advance(Unknown Source)
   at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
   at com.fs.starfarer.combat.CombatState.traverse(Unknown Source)
   at com.fs.state.AppDriver.begin(Unknown Source)
   at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
   at com.fs.starfarer.StarfarerLauncher$2.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)

After a lot of testing i figured out that this happens only while fighting against fighters, with siege mode turned on and with the tartarus... I'm not sure if there is another ship with the same abilety and if it would happen with this ship too.
The situation when it happens: While a fighter wreck is reaching the border of the battlefield and siege mode is turned on, it gives me a CDT. The problem is, it is not 100% reproducible. But some conditions make it occure more often. There have to be a lot of fighters/bombers on the battlefield. It seems it happens more frequently (or only... not shure yet) when in siege mode, turning off the schield because flux is very high and then turning them on again (never leaving siege mode).
The tartarus is  equiped with SRA weapons (from front to rear: 2x Medium CEPC (front mounts), Wavepulse Cannon, Medium CEPC (first medium Turret), 3 x Scatter CEPC (the other 3 medium turret mounts) and 4 x light CEPC)
I failed to repruduce it with vanilla only and starsector+. Until now it happened only with SS+ + Nexerelin. Problem is i didn't had the time to test it with all modcombinations plus the exact same equipment. So maybe it can happen in vanilla or SS+ too if i get hands on the same weapons. The Problem is the starting location in Nex is at a SRA Planet with the weapons on the market and with SS+ or vanilla you start at a different Planet.

I hope this will help you to pinpoint the Problem. I have no problems with other faction mods or modcombinations while SRA is turned off.

Thanks for the great work!

I've looked over the code again, and I'm still not seeing anything wrong - or, in fact, any way that the Shadowyards' Tartarus could be causing what appears to be a CTD with a purely vanilla code stack.

Now, there is a potential hole in the MSTartarusShieldFinagler - if engine.getShips returns a list containing null, that'd trigger a crash.  Maybe we should guard against that.  But if that were the problem, I'd expect to see that class in the stack trace, and it's not there.  Anyone else have any ideas?
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Weird Null Pointer crash
« Reply #1 on: December 27, 2015, 10:37:20 AM »

Now, there is a potential hole in the MSTartarusShieldFinagler - if engine.getShips returns a list containing null, that'd trigger a crash.  Maybe we should guard against that.  But if that were the problem, I'd expect to see that class in the stack trace, and it's not there.  Anyone else have any ideas?

That shouldn't happen - not something I'd suggest guarding against, and I'm pretty paranoid. (Famous last words?)

Looking at the stack trace, the crash happens in the ShipEngineControllerAPI implementation class, when it's computing the effective stats of a ship's engines - figuring out what fraction is disabled, whether to apply the zero-flux boost, whether to flame out or bring some engines back online, that sort of thing.

Just looking at that code, though, I'm not seeing anything obvious where it would crash. If a ship didn't have any engines, something weird might happen, but aside from that? Not sure. I mean, clearly something's going wrong, but what exactly, it's hard to say.

Logged

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Weird Null Pointer crash
« Reply #2 on: December 27, 2015, 11:34:48 AM »

Hmmm... given the description of this being an engine related problem... well, it seems a bit strange but I wonder if it might not be related to the engine related effects of the system; in addition to the systems other effects,  Siege Mode sharply reduces the ships max speed (by 80%) and increases it's turn rate and turn acceleration (by a flat 30 and 45 respectively).  I'm not sure why this could cause a problem (or why it would not emerge outside of such a particular instance) but it seems to be the only possibly related thing.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Weird Null Pointer crash
« Reply #3 on: December 27, 2015, 11:43:47 AM »

Actually, there's one more hidden effect: Siege Mode reduces the zero flux speed boost to zero (actually, a flat -50, which could maybe push it negative?).  Could that be causing problems?  It'd fit with the reported behavior of this crash only happening when siege mode is on but the shield is off...
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Weird Null Pointer crash
« Reply #4 on: December 27, 2015, 12:21:17 PM »

Nice catch - that was it. Fixed for the next release; in the meantime any non-zero value should do.

Surprised this hasn't come up earlier - seems like it should happen every time by just activating that system and turning off the shield.
« Last Edit: December 27, 2015, 12:28:11 PM by Alex »
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Weird Null Pointer crash
« Reply #5 on: December 27, 2015, 12:29:48 PM »

Ooh.  I bet it only happens when turning off shields when you have the level 10 skill perk from Helmsmanship & your flux is below 25% - that'd explain why I couldn't replicate this in missions.
Edit: And why it only just now started breaking, since before if you had level 10 helmsmanship, you also had an increased zero flux speed boost!

Okay!  Yay, we know what's going on!  So lessee.  How to fix...

Quote
       stats.getZeroFluxSpeedBoost().modifyFlat(id, -50f * effectLevel); // this very quietly mostly-disables the zero flux speed boost.

Replace that with something like:
Quote
       stats.getZeroFluxSpeedBoost().modifyPercent(id, -50f * effectLevel); // this very quietly mostly-disables the zero flux speed boost.

That should leave the zero flux boost at a non-zero value.
Edit: And actually put it back where it was when Helmsmanship increased the zero flux speed boost; I reduced it because +75 speed was just too much of a bonus on top of a ship system that's supposed to slow you down.
« Last Edit: December 27, 2015, 12:39:14 PM by Wyvern »
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Weird Null Pointer crash
« Reply #6 on: December 27, 2015, 12:38:22 PM »

Or, say, modifyMult(id, 1f - 0.99f * effectLevel). Then you'd get basically the same impact - almost zero - sans the crashing. With the modifyPercent, you're reducing it by half, and only if nothing else modified it as well. modifyMult seems more functionally appropriate for a "turn this off entirely" override-type mechanic.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Weird Null Pointer crash
« Reply #7 on: December 27, 2015, 12:41:39 PM »

modifyMult seems more functionally appropriate for a "turn this off entirely" override-type mechanic.

Hm.  Might want to use modifyMult( id, 1f - .5f * effectLevel ) then - as noted in edit above, this was never intended to turn off the speed boost entirely, merely reduce it to a manageable value.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Weird Null Pointer crash
« Reply #8 on: December 27, 2015, 12:42:51 PM »

Hm.  Might want to use modifyMult( id, 1f - .5f * effectLevel ) then - as noted in edit above, this was never intended to turn off the speed boost entirely, merely reduce it to a manageable value.

Ah - sorry, didn't catch that. Yeah, that sounds like the right way to accomplish that, then.
Logged

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Weird Null Pointer crash
« Reply #9 on: December 27, 2015, 12:54:49 PM »

Surprised this hasn't come up earlier - seems like it should happen every time by just activating that system and turning off the shield.

I guess no one with Helmsmanship 10 happened to be flying one of these things before officers went in?  It's a bit odd, yeah; as for why it hadn't come up immediately, the system itself generates a negligible amount of flux to keep it from getting the flux boost normally, so it basically needed a skilled character to bring the bug to light.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Weird Null Pointer crash
« Reply #10 on: December 27, 2015, 01:08:56 PM »

I guess no one with Helmsmanship 10 happened to be flying one of these things before officers went in?  It's a bit odd, yeah; as for why it hadn't come up immediately, the system itself generates a negligible amount of flux to keep it from getting the flux boost normally, so it basically needed a skilled character to bring the bug to light.
Before officers went in, helmsmanship 5 granted +25 to the zero flux speed boost - at which point the -50 would bring it down to 25 instead of zero, and since you can't get helmsmanship 10 without also having 5...  We didn't start seeing problems until the Helmsmanship 5 perk was changed to maneuverability.
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Weird Null Pointer crash
« Reply #11 on: December 27, 2015, 01:34:10 PM »

Ahh. Fun stuff!
Logged