LGhassen / Scatterer

Atmospheric scattering mod for KSP
Other
190 stars 51 forks source link

NRE spam at Space Center scene and in flight, with unusual Kopernicus config #28

Closed gordonfpanam closed 6 years ago

gordonfpanam commented 7 years ago

I'm working on Module Manager patches for Alien Space Programs to accommodate two worlds changing names; the new home world is Duna and Kerbin gets replaced with a stand-in named "Bin." For the most part, this works with Module Manager patches that replace Kerbin with Bin. I'm testing this on KSP 1.3 with Kopernicus 1.3.0-2 until they fix LandControl and get scatter objects working again.

For the Eve and Laythe editions of this hack, this seems to work. For Duna, I get NRE spam at the Space Center scene and any flight scene on Duna:

[EXC 16:07:04.428] NullReferenceException: Object reference not set to an instance of an object scatterer.RefractionCamera.OnPreCull ()

This stops when I switch to another world, or go to the map or tracking station.

The only thing different between Duna and the rest is the lack of ocean. I tried hacking in a hidden ocean, but this didn't seem to make any difference.

Oddly, the Duna atmosphere still behaves as expected in both flight and map views.

What else can I check for that would help troubleshoot this? Should I make other changes to my configs to avoid this?

@Scatterer_planetsList:NEEDS[scatterer]:AFTER[DunaSpaceProgram]
{       
    @scattererCelestialBodies
    {
        @Item,0 //Kerbin
        {
            %celestialBodyName = Bin
            %transformName = Bin
        }
    }
}

@Scatterer_ocean:NEEDS[scatterer]:AFTER[DunaSpaceProgram]
{
    @Ocean[Kerbin]
    {
        %name = Bin
    }
}

@Scatterer_atmosphere:NEEDS[scatterer]:AFTER[DunaSpaceProgram]
{
    @Atmo[Kerbin]
    {
        %name = Bin
    }
}

Kopernicus identifies these worlds after displayName and cbNameLater take effect:

[LOG 16:06:53]: Found Body: Sun:0 -> SOI = Infinity, Hill Sphere = Infinity
[LOG 16:06:53]: Found Body: Duna:1 -> SOI = 47921949.369738, Hill Sphere = 125063736.748336
[LOG 16:06:53]: Found Body: Mun:2 -> SOI = 2429559.11656475, Hill Sphere = 3170563.33757116
[LOG 16:06:53]: Found Body: Minmus:3 -> SOI = 2247428.3879023, Hill Sphere = 3730392.49065433
[LOG 16:06:53]: Found Body: Moho:4 -> SOI = 9646663.02332811, Hill Sphere = 22060314.8155466
[LOG 16:06:53]: Found Body: Eve:5 -> SOI = 85109364.7382441, Hill Sphere = 185949494.965972
[LOG 16:06:53]: Found Body: Ike:6 -> SOI = 1049598.93931162, Hill Sphere = 1225978.58343315
[LOG 16:06:53]: Found Body: Jool:7 -> SOI = 2455985185.42347, Hill Sphere = 4065824625.34358
[LOG 16:06:53]: Found Body: Bin:8 -> SOI = 84159286.4796305, Hill Sphere = 196414707.77848
[LOG 16:06:53]: Found Body: Vall:9 -> SOI = 2406401.44479404, Hill Sphere = 3893201.55262436
[LOG 16:06:53]: Found Body: Bop:10 -> SOI = 1221060.86284253, Hill Sphere = 2029674.44211376
[LOG 16:06:53]: Found Body: Tylo:11 -> SOI = 10856518.3683586, Hill Sphere = 14757877.6267184
[LOG 16:06:53]: Found Body: Gilly:12 -> SOI = 126123.271704568, Hill Sphere = 142427.423478875
[LOG 16:06:53]: Found Body: Pol:13 -> SOI = 1042138.89230178, Hill Sphere = 2038945.47430365
[LOG 16:06:53]: Found Body: Dres:14 -> SOI = 32832839.5767762, Hill Sphere = 92059713.5005964
[LOG 16:06:53]: Found Body: Eeloo:15 -> SOI = 119082941.647812, Hill Sphere = 266016718.015223
[LOG 16:06:53]: Found Body: Laythe:16 -> SOI = 3723645.81113302, Hill Sphere = 5186318.66159496
LGhassen commented 7 years ago

Does everything work fine if you disable refraction from main menu? What about if you disable ocean shaders?

Did you make sure to set hasOcean= false?

Is the transformName for Duna "Duna" or "Kerbin"? I don't know how changing the homeworld works.

gordonfpanam commented 7 years ago

The NRE spam does go away if I turn ocean refractions off. So we have that as a workaround. And Duna in planetsList.cfg is using the defaults, including hasOcean = false. My Module Manager patches only rename Kerbin to Bin so Scatterer can use Kerbin's configs for Bin, and Scatterer seems to be doing the rest on its own, correctly, with regards to atmosphere and ocean effects otherwise.

Remember this is only happening with Duna as the home world. Laythe or Eve as home worlds seem to be OK without NRE spamming.

It looks like Kopernicus still calls the home world "Kerbin" because KSP works that way and that's it. Scatterer is identifying the worlds with atmosphere this way:

[LOG 16:07:01.121] [Scatterer] Celestial Body: Bin (CelestialBody)
[LOG 16:07:01.122] [Scatterer] Found: Bin / Bin
[LOG 16:07:01.122] [Scatterer] Celestial Body: Kerbin (CelestialBody)
[LOG 16:07:01.123] [Scatterer] Found: Duna / Duna
[LOG 16:07:01.123] [Scatterer] Celestial Body: Laythe (CelestialBody)
[LOG 16:07:01.123] [Scatterer] Found: Laythe / Laythe
[LOG 16:07:01.124] [Scatterer] Celestial Body: Jool (CelestialBody)
[LOG 16:07:01.124] [Scatterer] Found: Jool / Jool
[LOG 16:07:01.125] [Scatterer] Celestial Body: Eve (CelestialBody)
[LOG 16:07:01.125] [Scatterer] Found: Eve / Eve

Note that celestial body 'Kerbin' is found as 'Duna / Duna.' The subsequent log entries seem to refer to Duna by name when logging details of the current home world, up until this first exception occurs:

[LOG 16:07:04.228] [Scatterer] Error calling clouds2d.reassign() on planet: DunaSystem.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
  at System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[System.Object]].get_Item (System.String key) [0x00000] in <filename unknown>:0 
  at scatterer.SkyNode.UpdateNode () [0x00000] in <filename unknown>:0 
[ERR 16:07:04.244] [SurfaceObject]: Cannot return to original parent, it no longer exists.
[LOG 16:07:04.245] [Kopernicus] Fixed SpaceCenterCamera
[LOG 16:07:04.246] [UiApp] Awake: KSPedia
[LOG 16:07:04.246] [ApplicationLauncher] OnSceneLoadedGUIReady: scene SPACECENTER ShouldBeVisible() True ShouldBeOnTop() False iIsPositionedAtTop True
[LOG 16:07:04.247] [ApplicationLauncher] SpawnSimpleLayout: HorizontalRightLeft
[LOG 16:07:04.249] [ApplicationLauncher] SetVisible: 
[LOG 16:07:04.250] [Kopernicus]: StarLightSwitcher: Set active star => Sun
[LOG 16:07:04.309] [UIApp] OnDestroy: ContractsApp
[EXC 16:07:04.313] NullReferenceException: Object reference not set to an instance of an object
    scatterer.RefractionCamera.OnPreCull ()
[LOG 16:07:04.371] [Scatterer] Sky switched to local mode
[LOG 16:07:04.373] [MessageSystem] Reposition 0.02 14416
[EXC 16:07:04.428] NullReferenceException: Object reference not set to an instance of an object
    scatterer.RefractionCamera.OnPreCull ()

KSP.zip

Here is the log. The configuration for Duna in Kopernicus starts off like this:

    %Body[Kerbin]
    {
        //New home world for internal use, must be named 'Kerbin' at least at first
        name = Kerbin
        //Legacy cbNameLater, I might remove it, replaced with displayName in Properties
        cbNameLater = Duna
        Template
        {
            //"specifically make sure you have no planets with a 'Kerbin' template other than the home planet."
            //-- Sigma88
            name = Kerbin
            removePQSMods = PQSLandControl,QuadEnhanceCoast,VertexHeightMap,VertexHeightNoiseVertHeightCurve2,VertexRidgedAltitudeCurve,VertexSimplexHeightAbsolute
            removeOcean = True
        }
        Properties
        {
            //displayName replaces cbNameLater for localization support, also supports KSP 1.2 still
            displayName = Duna

...and doesn't have an Ocean {} section defined. The NRE spam happens whether I include an ocean or not.

This appears to occur in KSP 1.2.2 as well as 1.3 with the same Kopernicus config.

LGhassen commented 7 years ago

Send me your configs because there is something funky going on with the naming.

gordonfpanam commented 7 years ago

Gladly.

They're readily available here at my (now out-of-date) ASP fork. Or you can try GregroxMun's official 1.0 release with Duna set as the home world.

Poodmund commented 7 years ago

@gordonfpanam did this issue ever get resolved as I am receiving exactly the same symptoms with OPM when I am orbiting Thatmo, a moon of Neidon? It is a body with no ocean as yours was too so I am not sure why Scatterer's refraction is trying to kick in.

EDIT: In addition to the above, the NulRefs start as soon as I go within PQS Fade In altitude range. So it seems to be doing it as soon as the PQS rendering happens.

This occurs also at Duna using a Vanilla install of KSP and Scatterer. The logs are attached.

You can recreate these logs by booting up a Vanilla KSP install with only Scatterer installed. Put a vessel into orbit around Duna within Duna's PQS load range (under 100km). Go back to the tracking station to change the in-game camera mode, then go back to the vessel at Duna and you will see the Null Refs spamming in the console.

I guess this is because there is no ocean loaded on the PQS for the refractionCamera to instantiate itself on and therefore it is throwing the exception.

KSP.log output_log.txt

EDIT EDIT: It seems this occurs around any body, not just those included within Scatterer's planetList node. You can do the same around The Mun and the null refs will appear.

TL;DR - Null Refs occur when orbiting any body with no Ocean, within the PQS fade in range (when PQS is being rendered).

gordonfpanam commented 7 years ago

EVEandScatterer-RestoredDuna.log EVEandScatterer-Bin.log EveAndScatterer-Duna.log EVEandScatterer-Eve.log EVEandScatterer-Minmus.log

I'm running into this, still, with the current edition of Alien Space Programs that includes Minmus and Tylo as home world settings. Here are five sets of ksp.log with different home world settings.

The exception spam occurs when a craft we're in control of (or has focus of) is on or near a home world that has no ocean. It's happening on Duna, RestoredDuna, and Minmus. It doesn't happen on Eve or (Ker)Bin. And it appears to be specific to refraction effects still, as turning refraction off stops the NRE spam.

LGhassen commented 6 years ago

Hello guys, can you test if this fix works? Thank you

https://forum.kerbalspaceprogram.com/index.php?/topic/103963-wip12213-scatterer-atmospheric-scattering-v00320-0320b-06072017-water-refraction/&do=findComment&comment=3209463