Skip to content

Commit

Permalink
fix crash with no local components
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBatesNZ committed Apr 20, 2020
1 parent 17eabf0 commit fad2be4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion engine/src/main/java/org/destinationsol/SolApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

@API
Expand Down Expand Up @@ -127,9 +128,13 @@ public void create() {

context.put(ComponentSystemManager.class, new ComponentSystemManager(moduleManager.getEnvironment(), context));

// Big, fat, ugly HACK to get a working classloader
// Serialisation and thus a classloader is not needed when there are no components
Iterator<Class<? extends Component>> componentClasses =
moduleManager.getEnvironment().getSubtypesOf(Component.class).iterator();
SerialisationManager serialisationManager = new SerialisationManager(
SaveManager.getResourcePath("entity_store.dat"), entitySystemManager.getEntityManager(),
moduleManager.getEnvironment().getSubtypesOf(Component.class).iterator().next().getClassLoader());
componentClasses.hasNext() ? componentClasses.next().getClassLoader() : null);
context.put(SerialisationManager.class, serialisationManager);

logger.info("\n\n ------------------------------------------------------------ \n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public void serialise() throws IllegalArgumentException, IllegalAccessException,

public void deserialise() throws IOException, ClassNotFoundException, InstantiationException,
IllegalAccessException, NoSuchFieldException {
if (classLoader == null) {
logger.warn("Trying to deserialise with Null classloader. Aborting");
return;
}

FileInputStream input = new FileInputStream(file);
EntityData.EntityStore store = EntityData.EntityStore.parseFrom(input);
Expand Down

0 comments on commit fad2be4

Please sign in to comment.