Fix error from flushing on different thread

This commit is contained in:
Jesse Boyd 2016-09-24 14:41:33 +10:00
parent d4fd374caa
commit d61c21f60e
2 changed files with 78 additions and 70 deletions

View File

@ -134,6 +134,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
@Override @Override
public boolean flush() { public boolean flush() {
synchronized (this) {
super.flush(); super.flush();
boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null; boolean flushed = osBD != null || osNBTF != null || osNBTT != null && osENTCF != null || osENTCT != null;
try { try {
@ -162,6 +163,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
} }
return flushed; return flushed;
} }
}
@Override @Override
public int getCompressedSize() { public int getCompressedSize() {
@ -199,12 +201,14 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
if (osBD != null) { if (osBD != null) {
return osBD; return osBD;
} }
synchronized (this) {
bdFile.getParentFile().mkdirs(); bdFile.getParentFile().mkdirs();
bdFile.createNewFile(); bdFile.createNewFile();
osBD = getCompressedOS(new FileOutputStream(bdFile)); osBD = getCompressedOS(new FileOutputStream(bdFile));
writeHeader(osBD, x, y, z); writeHeader(osBD, x, y, z);
return osBD; return osBD;
} }
}
@Override @Override
public NBTOutputStream getEntityCreateOS() throws IOException { public NBTOutputStream getEntityCreateOS() throws IOException {

View File

@ -48,6 +48,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
@Override @Override
public boolean flush() { public boolean flush() {
synchronized (this) {
super.flush(); super.flush();
try { try {
if (idsStream != null) { if (idsStream != null) {
@ -85,6 +86,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
} catch (IOException e) { } catch (IOException e) {
MainUtil.handleError(e); MainUtil.handleError(e);
} }
}
return false; return false;
} }
@ -110,12 +112,14 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
if (idsStreamZip != null) { if (idsStreamZip != null) {
return idsStreamZip; return idsStreamZip;
} }
synchronized (this) {
setOrigin(x, z); setOrigin(x, z);
idsStream = new FastByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); idsStream = new FastByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE);
idsStreamZip = getCompressedOS(idsStream); idsStreamZip = getCompressedOS(idsStream);
writeHeader(idsStreamZip, x, y, z); writeHeader(idsStreamZip, x, y, z);
return idsStreamZip; return idsStreamZip;
} }
}
@Override @Override
public InputStream getBlockIS() throws IOException { public InputStream getBlockIS() throws IOException {