shadowmage45 / TexturesUnlimited

KSP Shader, Texture, and Modeling Utilities
GNU General Public License v3.0
29 stars 17 forks source link

Causes Null Reference in KSP API when model is shared between parts #14

Closed Electrocutor closed 7 years ago

Electrocutor commented 7 years ago

Example: USI's ORE_DRILL MODEL { model = Squad/Parts/Resources/RadialDrill/TriBitDrill texture = TriBitDrill, UmbraSpaceIndustries/KarbonitePlus/Assets/TriBitDrill_GY scale = 2,2,2 }

The place the exception is being thrown is the KSP API: PartLoader.ReplaceTextures.

Suspect TU cfg: model = Squad/Parts/Resources/RadialDrill/TriBitDrill TEXTURE { shader = SSTU/PBR/Metallic

    texture = _MetallicGlossMap,TexturesUnlimited_Stock/Textures/silver

    excludeMesh = flagTransform
    excludeMesh = Flag
}
shadowmage45 commented 7 years ago

Thanks for the report; will be putting this one on the 'priority fix' list as it interferes with stock code in some fashion.

No idea how it could be interfering, but I'll dig into it and find out.

Edit:

Electrocutor commented 7 years ago

If that is the case, you can use the builtin textures for white and black instead of generating them each time: Texture2D.whiteTexture Texture2D.blackTexture

I also see that Texture2D is where the texture tiling modes are set.

shadowmage45 commented 7 years ago

Have a preliminary fix in place that assigns textures to any empty texture slot on any model/mesh that is adjusted through the 'default shader assignments' method.

It has removed the errors from the log when loading stock parts with replaced textures, and am investigating to make sure it hasn't introduced any other problems.

Still had to dynamically create a default Normal Map texture (64x64, flat normals), as Unity doesn't offer a default value for those. Used Texture2D.blackTexture for the placeholder for both DIFF and GLOW slots.