Skip to content

Commit

Permalink
Export fix for graphics null pointers (#176)
Browse files Browse the repository at this point in the history
Added lots of null checks (Sylvain on Christian's computer).
  • Loading branch information
christiandebuys authored Apr 22, 2024
1 parent 865a158 commit 0dc83cf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,22 @@ private static void setResourcesClassLoaderRecursive(File file, YoGraphicDefinit
}
else if (yoGraphicDefinition instanceof YoGraphicGroupDefinition yoGraphicGroupDefinition)
{
for (YoGraphicDefinition child : yoGraphicGroupDefinition.getChildren())
if (yoGraphicGroupDefinition.getChildren() != null)
{
setResourcesClassLoaderRecursive(file, child);
for (YoGraphicDefinition child : yoGraphicGroupDefinition.getChildren())
{
setResourcesClassLoaderRecursive(file, child);
}
}
}
else if (yoGraphicDefinition instanceof YoGraphicListDefinition yoGraphicListDefinition)
{
for (YoGraphicDefinition child : yoGraphicListDefinition.getYoGraphics())
if (yoGraphicListDefinition.getYoGraphics() != null)
{
setResourcesClassLoaderRecursive(file, child);
for (YoGraphicDefinition child : yoGraphicListDefinition.getYoGraphics())
{
setResourcesClassLoaderRecursive(file, child);
}
}
}
}
Expand Down Expand Up @@ -324,16 +330,22 @@ private static void processYoGraphicResources(File yoGraphicFile, YoGraphicDefin
}
else if (start instanceof YoGraphicGroupDefinition yoGraphicGroupDefinition)
{
for (YoGraphicDefinition child : yoGraphicGroupDefinition.getChildren())
if (yoGraphicGroupDefinition.getChildren() != null)
{
processYoGraphicResources(yoGraphicFile, child, resourcesDirectory);
for (YoGraphicDefinition child : yoGraphicGroupDefinition.getChildren())
{
processYoGraphicResources(yoGraphicFile, child, resourcesDirectory);
}
}
}
else if (start instanceof YoGraphicListDefinition yoGraphicListDefinition)
{
for (YoGraphicDefinition child : yoGraphicListDefinition.getYoGraphics())
if (yoGraphicListDefinition.getYoGraphics() != null)
{
processYoGraphicResources(yoGraphicFile, child, resourcesDirectory);
for (YoGraphicDefinition child : yoGraphicListDefinition.getYoGraphics())
{
processYoGraphicResources(yoGraphicFile, child, resourcesDirectory);
}
}
}
}
Expand Down Expand Up @@ -578,20 +590,29 @@ private static void processResources(File robotFile, RobotDefinition robotDefini
private static void processResources(File baseFile, RigidBodyDefinition rigidBody, File resourceDirectory, ClassLoader defaultClassLoader)
throws IOException, URISyntaxException
{
for (VisualDefinition visualDefinition : rigidBody.getVisualDefinitions())
if (rigidBody.getVisualDefinitions() != null)
{
processResources(baseFile, visualDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
processResources(baseFile, visualDefinition.getMaterialDefinition(), resourceDirectory, defaultClassLoader);
for (VisualDefinition visualDefinition : rigidBody.getVisualDefinitions())
{
processResources(baseFile, visualDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
processResources(baseFile, visualDefinition.getMaterialDefinition(), resourceDirectory, defaultClassLoader);
}
}

for (CollisionShapeDefinition collisionShapeDefinition : rigidBody.getCollisionShapeDefinitions())
if (rigidBody.getCollisionShapeDefinitions() != null)
{
processResources(baseFile, collisionShapeDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
for (CollisionShapeDefinition collisionShapeDefinition : rigidBody.getCollisionShapeDefinitions())
{
processResources(baseFile, collisionShapeDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
}
}

for (JointDefinition jointDefinition : rigidBody.getChildrenJoints())
if (rigidBody.getChildrenJoints() != null)
{
processResources(baseFile, jointDefinition.getSuccessor(), resourceDirectory, defaultClassLoader);
for (JointDefinition jointDefinition : rigidBody.getChildrenJoints())
{
processResources(baseFile, jointDefinition.getSuccessor(), resourceDirectory, defaultClassLoader);
}
}
}

Expand All @@ -611,15 +632,21 @@ private static void processResources(File terrainObjectFile,
{
TerrainObjectDefinition copy = new TerrainObjectDefinition(terrainObjectDefinition);

for (VisualDefinition visualDefinition : copy.getVisualDefinitions())
if (copy.getVisualDefinitions() != null)
{
processResources(terrainObjectFile, visualDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
processResources(terrainObjectFile, visualDefinition.getMaterialDefinition(), resourceDirectory, defaultClassLoader);
for (VisualDefinition visualDefinition : copy.getVisualDefinitions())
{
processResources(terrainObjectFile, visualDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
processResources(terrainObjectFile, visualDefinition.getMaterialDefinition(), resourceDirectory, defaultClassLoader);
}
}

for (CollisionShapeDefinition collisionShapeDefinition : copy.getCollisionShapeDefinitions())
if (copy.getCollisionShapeDefinitions() != null)
{
processResources(terrainObjectFile, collisionShapeDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
for (CollisionShapeDefinition collisionShapeDefinition : copy.getCollisionShapeDefinitions())
{
processResources(terrainObjectFile, collisionShapeDefinition.getGeometryDefinition(), resourceDirectory, defaultClassLoader);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
@XmlRootElement(name = "YoGraphicGroup")
public class YoGraphicGroupDefinition extends YoGraphicDefinition
{
/** The list of children the group contains. */
/**
* The list of children the group contains.
*/
private List<YoGraphicDefinition> children;

/**
Expand Down Expand Up @@ -208,7 +210,8 @@ public void mergeNestedGroupsByName()
if (subGroup.getName().equals(otherSubGroup.getName()))
{
children.remove(j);
subGroup.getChildren().addAll(otherSubGroup.getChildren());
if (otherSubGroup.getChildren() != null)
subGroup.getChildren().addAll(otherSubGroup.getChildren());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;

/**
* A {@code YoGraphicListDefinition} is convenience class that allows to gather several
Expand All @@ -17,7 +14,9 @@
@XmlRootElement(name = "YoGraphicList")
public class YoGraphicListDefinition extends YoGraphicDefinition
{
/** The internal list of yoGraphics. */
/**
* The internal list of yoGraphics.
*/
private List<YoGraphicDefinition> yoGraphics = new ArrayList<>();

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ public YoGraphicListDefinition(YoGraphicListDefinition other)
{
super(other);
if (other.yoGraphics != null)
yoGraphics = other.yoGraphics.stream().map(YoGraphicDefinition::copy).toList();
yoGraphics = other.yoGraphics.stream().filter(Objects::nonNull).map(YoGraphicDefinition::copy).toList();
}

@Override
Expand Down Expand Up @@ -158,7 +157,8 @@ public void mergeGroupsByName()
if (subGroup.getName().equals(otherSubGroup.getName()))
{
yoGraphics.remove(j);
subGroup.getChildren().addAll(otherSubGroup.getChildren());
if (otherSubGroup.getChildren() != null)
subGroup.getChildren().addAll(otherSubGroup.getChildren());
}
}
}
Expand Down

0 comments on commit 0dc83cf

Please sign in to comment.