Merge pull request #744 from teyrana/742-load-crash

Resolves #742 - Crash on rocket-load
This commit is contained in:
Daniel Williams 2020-08-14 19:01:03 -04:00 committed by GitHub
commit 56135aafd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 33 deletions

View File

@ -577,34 +577,33 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
* @return the previous SymmetricComponent, or null. * @return the previous SymmetricComponent, or null.
*/ */
public final SymmetricComponent getPreviousSymmetricComponent() { public final SymmetricComponent getPreviousSymmetricComponent() {
if(null == this.parent) { if((null == this.parent) || (null == this.parent.getParent())){
return null; return null;
} }
final ComponentAssembly assembly = this.getAssembly();
// might be: (a) Rocket -- for Centerline/Axial stages // might be: (a) Rocket -- for Centerline/Axial stages
// (b) BodyTube -- for Parallel Stages & PodSets // (b) BodyTube -- for Parallel Stages & PodSets
final RocketComponent assemblyParent = assembly.getParent(); final RocketComponent grandParent = this.parent.getParent();
// note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. int searchParentIndex = grandParent.getChildPosition(this.parent); // position of stage w/in parent
int assemblyIndex = assemblyParent.getChildPosition(assembly); // position of stage w/in parent int searchSiblingIndex = this.parent.getChildPosition(this)-1; // guess at index of previous stage
int symmetricIndex = this.parent.getChildPosition(this)-1; // guess at index of previous stage
while( 0 <= assemblyIndex ) { while( 0 <= searchParentIndex ) {
final RocketComponent searchAssembly = assemblyParent.getChild(assemblyIndex); final RocketComponent searchParent = grandParent.getChild(searchParentIndex);
if(searchAssembly instanceof ComponentAssembly){ if(searchParent instanceof ComponentAssembly){
while (0 <= symmetricIndex) { while (0 <= searchSiblingIndex) {
final RocketComponent previousSymmetric = searchAssembly.getChild(symmetricIndex); final RocketComponent searchSibling = searchParent.getChild(searchSiblingIndex);
if (searchSibling instanceof SymmetricComponent) {
if (previousSymmetric instanceof SymmetricComponent) { return (SymmetricComponent) searchSibling;
return (SymmetricComponent) previousSymmetric;
} }
--symmetricIndex; --searchSiblingIndex;
} }
} }
--assemblyIndex; --searchParentIndex;
symmetricIndex = searchAssembly.getChildCount() - 1; if( 0 <= searchParentIndex){
searchSiblingIndex = grandParent.getChild(searchParentIndex).getChildCount() - 1;
}
} }
return null; return null;
} }
@ -615,34 +614,33 @@ public abstract class SymmetricComponent extends BodyComponent implements BoxBou
* @return the next SymmetricComponent, or null. * @return the next SymmetricComponent, or null.
*/ */
public final SymmetricComponent getNextSymmetricComponent() { public final SymmetricComponent getNextSymmetricComponent() {
if(null == this.parent) { if((null == this.parent) || (null == this.parent.getParent())){
return null; return null;
} }
final ComponentAssembly assembly = this.getAssembly();
// might be: (a) Rocket -- for centerline stages // might be: (a) Rocket -- for centerline stages
// (b) BodyTube -- for Parallel Stages // (b) BodyTube -- for Parallel Stages
final RocketComponent assemblyParent = assembly.getParent(); final RocketComponent grandParent = this.parent.getParent();
// note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one.
int assemblyIndex = assemblyParent.getChildPosition(assembly); int searchParentIndex = grandParent.getChildPosition(this.parent);
int symmetricIndex = this.parent.getChildPosition(this) + 1; int searchSiblingIndex = this.parent.getChildPosition(this) + 1;
while(assemblyIndex < assemblyParent.getChildCount()) { while(searchParentIndex < grandParent.getChildCount()) {
final RocketComponent searchAssembly = assemblyParent.getChild(assemblyIndex); final RocketComponent searchParent = grandParent.getChild(searchParentIndex);
if(searchAssembly instanceof ComponentAssembly){ if(searchParent instanceof ComponentAssembly){
while (symmetricIndex < searchAssembly.getChildCount()) { while (searchSiblingIndex < searchParent.getChildCount()) {
final RocketComponent nextSymmetric = searchAssembly.getChild(symmetricIndex); final RocketComponent searchSibling = searchParent.getChild(searchSiblingIndex);
if (nextSymmetric instanceof SymmetricComponent) { if (searchSibling instanceof SymmetricComponent) {
return (SymmetricComponent) nextSymmetric; return (SymmetricComponent) searchSibling;
} }
++symmetricIndex; ++searchSiblingIndex;
} }
} }
++assemblyIndex; ++searchParentIndex;
symmetricIndex = searchAssembly.getChildCount() - 1; searchSiblingIndex = 0;
} }
return null; return null;
} }

View File

@ -245,7 +245,7 @@ public class RocketTest extends BaseTestCase {
body.setOuterRadiusAutomatic(true); body.setOuterRadiusAutomatic(true);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
} }
{ // test auto-radius within a stage: body tube -> trailing transition { // test auto-radius within a stage: tail cone -> body tube
final BodyTube body = (BodyTube) booster.getChild(0); final BodyTube body = (BodyTube) booster.getChild(0);
assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON); assertEquals(" radius match: ", expRadius, body.getOuterRadius(), EPSILON);
final Transition tailCone = (Transition)booster.getChild(1); final Transition tailCone = (Transition)booster.getChild(1);