mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
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.
This commit is contained in:
parent
85a07e4a3c
commit
8b81e44481
@ -117,19 +117,17 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
}
|
}
|
||||||
case _ => 0
|
case _ => 0
|
||||||
}))
|
}))
|
||||||
val oldArchitecture = architecture
|
var newArchitecture: Architecture = null
|
||||||
architecture = null
|
|
||||||
components.find {
|
components.find {
|
||||||
case stack: ItemStack => Option(Driver.driverFor(stack, host.getClass)) match {
|
case stack: ItemStack => Option(Driver.driverFor(stack, host.getClass)) match {
|
||||||
case Some(driver: Processor) if driver.slot(stack) == Slot.CPU =>
|
case Some(driver: Processor) if driver.slot(stack) == Slot.CPU =>
|
||||||
Option(driver.architecture(stack)) match {
|
Option(driver.architecture(stack)) match {
|
||||||
case Some(clazz) =>
|
case Some(clazz) =>
|
||||||
if (oldArchitecture == null || oldArchitecture.getClass != clazz) {
|
if (architecture == null || architecture.getClass != clazz) {
|
||||||
architecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this)
|
newArchitecture = clazz.getConstructor(classOf[machine.Machine]).newInstance(this)
|
||||||
if (node.network != null) architecture.onConnect()
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
architecture = oldArchitecture
|
newArchitecture = architecture
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
case _ => false
|
case _ => false
|
||||||
@ -138,6 +136,12 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
|
|||||||
}
|
}
|
||||||
case _ => false
|
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))
|
hasMemory = Option(architecture).fold(false)(_.recomputeMemory(components))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user