diff --git a/src/binaryFileStorage/BinaryDataSource.java b/src/binaryFileStorage/BinaryDataSource.java index ccd07440..bb2888ba 100644 --- a/src/binaryFileStorage/BinaryDataSource.java +++ b/src/binaryFileStorage/BinaryDataSource.java @@ -41,6 +41,8 @@ public abstract class BinaryDataSource { private boolean saveUpdates = false; private BackgroundBinaryWriter backgroundBinaryWriter; + + public static final Object packSynchObject = new Object(); /** * Create a binary data source. These are used both to store data in binary @@ -224,11 +226,13 @@ public abstract class BinaryDataSource { * Then pack the data */ BinaryObjectData data; - if (pamDataUnit instanceof BackgroundDataUnit) { - data = getBackgroundBinaryWriter().packBackgroundData((BackgroundDataUnit) pamDataUnit); - } - else { - data = getPackedData(pamDataUnit); + synchronized (packSynchObject) { + if (pamDataUnit instanceof BackgroundDataUnit) { + data = getBackgroundBinaryWriter().packBackgroundData((BackgroundDataUnit) pamDataUnit); + } + else { + data = getPackedData(pamDataUnit); + } } /* * Then put it back to how it was a moment ago. diff --git a/src/networkTransfer/send/NetworkObjectPacker.java b/src/networkTransfer/send/NetworkObjectPacker.java index 08b9aa0d..ee3aac88 100644 --- a/src/networkTransfer/send/NetworkObjectPacker.java +++ b/src/networkTransfer/send/NetworkObjectPacker.java @@ -75,7 +75,10 @@ public class NetworkObjectPacker { BinaryDataSource binarySource = dataBlock.getBinaryDataSource(); int dataType2 = dataBlock.getQuickId(); - BinaryObjectData packedObject = binarySource.getPackedData(dataUnit); + BinaryObjectData packedObject = null; + synchronized (BinaryDataSource.packSynchObject) { + packedObject = binarySource.getPackedData(dataUnit); + } byte[] data = packedObject.getData(); int duDataLength = data.length + 12; DataUnitBaseData baseData = dataUnit.getBasicData();