Skip to content

Ensure parent frames always cover their children - #6469

Merged
sturnclaw merged 1 commit into
pioneerspacesim:masterfrom
sam52796:Fix_nested_frames
Nov 30, 2026
Merged

sturnclaw merged 1 commit into
pioneerspacesim:masterfrom
sam52796:Fix_nested_frames

Conversation

@sam52796

Copy link
Copy Markdown
Contributor

Fixes #5830

In order for ships to correctly find the frame of reference that they are currently in, the parent frames always have to enclose their children. Occasionally, a parent frame will be too small, so that the child is outside it. This then causes ships to get confused, since the algorithm they're using can't enter the child's frame of reference.

In particular, if the child is a space station, then ships can't dock or do collision detection with it, because everything is not in the frame that the code expects it to be in.

This pull request fixes a couple of issues that would cause frames to be the wrong size, and also adds a safety check that expands any still-too-small parent frames so that they cover their children.

Save games keep any wrong frame setup, so if you load the Shibata save in #5830 it appears to still be broken, however if you then jump out and then back into the system, everything is now working.

Comment thread src/Space.cpp Resolved
@sam52796

sam52796 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

A planet's moons are supposed to be within the planet's frame. That allows the frame determination code to find child frames within the parent. If you consider a solar system, everything is within the frame of the sun, but if you get close enough to a planet, the frame of reference switches to that planet. The same principle applies to moons around planets, and stations around moons.

The problem you may be thinking of is when a moon's orbit (and hence frame of reference) is too big and includes the planet - that's what was fixed in #6330. Basically, the hierarchy has to be enforced in both directions - parent frames should always include all their children, and child frames should not include the parent or each other.

The fix here is because the code uses hillRadius as if it's in metres, but GetSemiMajorAxis() returns the measurement in AU, so it needs to be multiplied by the AU constant to get a meaningful result. It's possible that the method used to return a value in m but was changed at some point and this code was never updated. Alternatively, I note that the Orbit class also has a method with the exact same name, which does return values in m, so it's possible that the original author of this code was confusing the SystemBody call with the Orbit one.

Either way, the calculation as written was wrong because it was using a far too small value for the Hill Radius in this instance. Fortunately this didn't cause problems very often because the following line looks at GetMaxChildOrbitalDistance(), so the parent frame was already big enough in most cases.

@fluffyfreak

Copy link
Copy Markdown
Contributor

Ah ha, thankyou for clearing all of that up, yes I was thinking of the Moon's orbit bug!

@sturnclaw sturnclaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks out on the most recently reported problem system - Rutoratto (0,-5,-8), which has a frame overlap on 3227-05-08 - so I'm merging it.

The general problem of Frame A overlaps sibling Frame B is still not solved (nor do I expect this PR to attempt to solve it), and I think that's typically an indicator of a malformed (physically impossible) system so not really worth tackling from Space.cpp.

@sturnclaw
sturnclaw merged commit f47103a into pioneerspacesim:master Nov 30, 2026
4 checks passed
@sam52796
sam52796 deleted the Fix_nested_frames branch November 30, 2026 12:22
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

Successfully merging this pull request may close these issues.

NPC ships stuck at orbital starport - frame not changing, docking not possible

3 participants