Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: [0.95.1a RC5] Crash on non-missile projectile creation with null weapon.  (Read 836 times)

prav

  • Captain
  • ****
  • Posts: 396
    • View Profile

This code worked without issue in 0.95a rc15.

Spawning a projectile with the following line causes an immediate NPE in spec loading.
Code
DamagingProjectileAPI shot = (DamagingProjectileAPI) engine.spawnProjectile(
ship,
null,
"prv_fracturer_system",
origin,
angle,
ship.getVelocity());
Attempted mitigations:
Removing the cast and assignment does not help.
Replacing "prv_fracturer_system" weapon id with "heavyblaster" or "lightac" does not help.

Replacing "prv_fracturer_system" weapon id with "bomb" bypasses the issue, the game does not crash.
Replacing the null WeaponAPI argument with ship.getAllWeapons().get(0) bypasses the issue, the game does not crash.

Stack trace
Code
1477399 [Thread-3] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException
java.lang.NullPointerException
at com.fs.starfarer.loading.specs.F.getMoveSpeed(Unknown Source)
at com.fs.starfarer.combat.entities.MovingRay.<init>(Unknown Source)
at com.fs.starfarer.loading.specs.a.Ò00000(Unknown Source)
at com.fs.starfarer.loading.specs.a.o00000(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.spawnProjectile(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.spawnProjectile(Unknown Source)
at scripts.shipsystems.prv_fracturer.apply(prv_fracturer.java:106)
at com.fs.starfarer.combat.systems.return.advance(Unknown Source)
at com.fs.starfarer.combat.entities.Ship.advance(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advanceInner(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.o00000(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

.proj
Code
{
"id":"prv_fracturer_shot",
"specClass":"projectile",
"onHitEffect":"scripts.weapons.prv_fracturer_OnHitEffect",
"spawnType":"BALLISTIC_AS_BEAM",
"collisionClass":"RAY_FIGHTER",
"collisionClassByFighter":"RAY_FIGHTER",
"length":45.0,
"width":7,
"fadeTime":0.3,
"fringeColor":[220,160,255,196],
"coreColor":[255,255,255,255],
"glowColor":[51,0,153,196],
"glowRadius":25,
"hitGlowRadius":25,
"textureScrollSpeed":64.0,
"pixelsPerTexel":5.0,
"bulletSprite":"graphics/missiles/shell_gauss_cannon.png"
}
.wpn
Code
{
  "id": "prv_fracturer_system",
"specClass":"projectile",
"type":"ENERGY",
"size":"MEDIUM",
"turretSprite":"graphics/weapons/blaster_turret_base.png",
"turretGlowSprite":"graphics/weapons/blaster_turret_glow.png",
"hardpointSprite":"graphics/weapons/blaster_hardpoint_base.png",
"hardpointGlowSprite":"graphics/weapons/blaster_hardpoint_glow.png",
#"glowColor":[155,100,255,255],
"glowColor":[51,0,153,196],
"turretOffsets":[10, 0],
"turretAngleOffsets":[0],
"hardpointOffsets":[15, 0],
"hardpointAngleOffsets":[0],
"barrelMode":"ALTERNATING", # or LINKED.  whether barrels fire at the same time or alternate.
"animationType":"GLOW_AND_FLASH",
"muzzleFlashSpec":{"length":40.0,   # only used if animationType = MUZZLE_FLASH
   "spread":15.0,
   "particleSizeMin":20.0,
   "particleSizeRange":10.0,
   "particleDuration":0.12,
   "particleCount":12,
   "particleColor":[51,0,153,196]},
#"autocharge":true,  # whether the weapon will continue charging and fire if the LMB is tapped instead of held
#"requiresFullCharge":true,  # for pulse weapons - whether the weapon will fire at a lower strength partial charge
"projectileSpecId":"prv_fracturer_shot",  # projectile that will be fired
"fireSoundTwo":"heavy_blaster_fire",
}
weapon_data.csv
Code
Fracture Packet,prv_fracturer_system,3,,0,2000,,150,,0,12,,,,,ENERGY,150,,,1,,,0,0,0,0,,700,,,,,,SYSTEM,,,prv Starworks,,Anti Flux,,,,,,,,,,87137
« Last Edit: December 12, 2021, 06:49:24 AM by prav »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: [0.95.1a RC5] Crash on non-missile projectile creation with null weapon.
« Reply #1 on: December 12, 2021, 09:04:42 AM »

Thank you for the report! Fixed.

(I think I'll need to hotfix for this one at some point; seems like the implications for modding are pretty important.)
Logged

theDragn

  • Captain
  • ****
  • Posts: 307
    • View Profile
[0.95.1a-RC5] CombatEngineAPI.spawnProjectile() causing crash with null weapon
« Reply #2 on: December 12, 2021, 12:33:00 PM »

Pretty much exactly what the title says. This crash only occurs when spawning a standard projectile- if it's spawning anything that's instanceof MissileAPI, it doesn't seem to crash.

Unsure if this is intentional or not, but it wasn't noted in the change log and it's different from previous behavior. For any other modders who run into this, the answer is to use CombatEngineAPI.createFakeWeapon() to create a dummy WeaponAPI and use that instead of null.

edit: oh yeah oops probably should have checked in here first, sorry alex
« Last Edit: December 12, 2021, 02:26:22 PM by theDragn »
Logged

theDragn

  • Captain
  • ****
  • Posts: 307
    • View Profile
Re: [0.95.1a RC5] Crash on non-missile projectile creation with null weapon.
« Reply #3 on: December 20, 2021, 02:44:33 PM »

Follow up to this-

the new spawnProjectile method (the one where you can specify a projectileSpecID) seems to cause an NPE whenever it's called, even when called with valid arguments.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24149
    • View Profile
Re: [0.95.1a RC5] Crash on non-missile projectile creation with null weapon.
« Reply #4 on: December 20, 2021, 02:54:43 PM »

Can you provide a stack trace and some example code that causes the error?

Edit: never mind; I see the crash. Not sure yet why it's happening, though.

Edit #2: ah, it looks like that crash is of the "it doesn't work because it couldn't possibly work" variety. Basically you can't specify a projectile ID there; it'll always grab the one from the weapon, and if it tries to grab one by ID (which it will if that's specified) then it grabs a half-baked one that hasn't been populated with the data from weapon_data.csv.
« Last Edit: December 20, 2021, 03:09:10 PM by Alex »
Logged

theDragn

  • Captain
  • ****
  • Posts: 307
    • View Profile
Re: [0.95.1a RC5] Crash on non-missile projectile creation with null weapon.
« Reply #5 on: December 21, 2021, 03:29:32 AM »

Ah, yeah, that would make sense. I suppose I was hoping for a magic reverse lookup for weapon from a projectile ID. Thanks!