Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No lift bug (NRE in ferram4.FARControllableSurface.get_MovableSection) #136

Closed
BrettRyland opened this issue Jul 4, 2022 · 1 comment
Closed

Comments

@BrettRyland
Copy link

Hey @dkavolis,
Some BDArmory users have been occasionally having issues where, after running KSP for a while, planes suddenly have no lift (the aerodynamic forces overlay shows nothing) and can't take off. I found a bunch of the following in their log:

[LOG 17:54:47.562] [FAR v0.16.0.5]: Updating vessel voxel for GreyHawk II MkXa
[EXC 17:54:47.563] NullReferenceException: Object reference not set to an instance of an object
  ferram4.FARControllableSurface.get_MovableSection () (at <1db2823b77704510ad0dd61fc9d23a0a>:0)
  ferram4.FARControllableSurface.FixedUpdate () (at <1db2823b77704510ad0dd61fc9d23a0a>:0)
  UnityEngine.DebugLogHandler:LogException(Exception, Object)
  ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
  UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)

This appears to be caused by part.FindModelTransform(transformName); returning null for some part (I suspect an EVA kerbal or the parachute in their inventory, the particular plane above uses an EVA kerbal in a command seat instead of a cockpit).
Adding in a null check fixes the issue, but means that part.FindModelTransform(transformName); is being called every fixedUpdate, so you may want to add a flag so that the check is only performed once and maybe give a warning in the log about the missing transform (in case the part is just badly configured and is fixable).

diff --git a/FerramAerospaceResearch/LEGACYferram4/FARControllableSurface.cs b/FerramAerospaceResearch/LEGACYferram4/FARControllableSurface.cs
index 426316c8..da6786bd 100644
--- a/FerramAerospaceResearch/LEGACYferram4/FARControllableSurface.cs
+++ b/FerramAerospaceResearch/LEGACYferram4/FARControllableSurface.cs
@@ -264,6 +264,7 @@ namespace ferram4
                 if (movableSection != null)
                     return movableSection;
                 movableSection = part.FindModelTransform(transformName); //And the transform
+                if (movableSection is null) return null;
                 if (!MovableOrigReady)
                 {
                     // In parts copied by symmetry, these fields should already be set,
@dkavolis
Copy link
Owner

dkavolis commented Jul 4, 2022

Thanks. Animations will now be disabled for parts without valid control surface models, no repeated calls to part.FindModelTransform but animations will not be reenabled if a valid transform is added which should be never/very rarely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants