From 1a66fbf7a982956e708a9500b177eef42b616f61 Mon Sep 17 00:00:00 2001 From: Vexatos Date: Tue, 14 Apr 2015 15:59:04 +0200 Subject: [PATCH 1/2] OPPM is apparently craftable now. --- src/main/resources/assets/opencomputers/loot/loot.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/loot/loot.properties b/src/main/resources/assets/opencomputers/loot/loot.properties index b7b1b1b53..4e9e7d187 100644 --- a/src/main/resources/assets/opencomputers/loot/loot.properties +++ b/src/main/resources/assets/opencomputers/loot/loot.properties @@ -12,7 +12,7 @@ Network=network:1:dyeLime OpenIRC=irc:1:dyeLightBlue OpenLoader=openloader:1:dyeMagenta OpenOS=openos:0:dyeGreen -OPPM=oppm:1:dyeCyan +OPPM=oppm:0:dyeCyan # Higher chance to find the dig program, because it has the most immediate # use - OpenOS is craftable and IRC can be downloaded once an internet card # is available - which one needs anyway, to use the program... From 8b81e44481a9390c739cdde0a0dd87f895365eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 15 Apr 2015 19:29:31 +0200 Subject: [PATCH 2/2] Should fix potential NPE in worker thread when arch is re-evaluated, closes #1070. May also fix other related problems of the architecture previously potentially changing mid-execution. --- .../scala/li/cil/oc/server/machine/Machine.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index b25c18bb4..f41ca7613 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -117,19 +117,17 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach } case _ => 0 })) - val oldArchitecture = architecture - architecture = null + var newArchitecture: Architecture = null components.find { case stack: ItemStack => Option(Driver.driverFor(stack, host.getClass)) match { case Some(driver: Processor) if driver.slot(stack) == Slot.CPU => Option(driver.architecture(stack)) match { case Some(clazz) => - if (oldArchitecture == null || oldArchitecture.getClass != clazz) { - architecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this) - if (node.network != null) architecture.onConnect() + if (architecture == null || architecture.getClass != clazz) { + newArchitecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this) } else { - architecture = oldArchitecture + newArchitecture = architecture } true case _ => false @@ -138,6 +136,12 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach } case _ => false } + // This needs to operate synchronized against the worker thread, to avoid the + // architecture changing while it is currently being executed. + if (newArchitecture != architecture) this.synchronized { + architecture = newArchitecture + if (architecture != null && node.network != null) architecture.onConnect() + } hasMemory = Option(architecture).fold(false)(_.recomputeMemory(components)) }