From 33e8cf2174a4c4dcfed3056376da8a3e9bdfb4de Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 20 Feb 2012 16:30:54 -0500 Subject: [PATCH] Fixed region object bug when deleting last chunk in region --- SubstrateCS/Source/Core/RegionFile.cs | 12 ++++++++++++ SubstrateCS/Source/Region.cs | 1 + 2 files changed, 13 insertions(+) diff --git a/SubstrateCS/Source/Core/RegionFile.cs b/SubstrateCS/Source/Core/RegionFile.cs index 1cab0b2..2051ad1 100644 --- a/SubstrateCS/Source/Core/RegionFile.cs +++ b/SubstrateCS/Source/Core/RegionFile.cs @@ -69,6 +69,10 @@ namespace Substrate.Core protected void ReadFile () { + if (_disposed) { + throw new ObjectDisposedException("RegionFile", "Attempting to use a RegionFile after it has been disposed."); + } + // Get last udpate time long newModified = -1; try { @@ -201,6 +205,10 @@ namespace Substrate.Core * the chunk is not found or an error occurs */ public Stream GetChunkDataInputStream(int x, int z) { + if (_disposed) { + throw new ObjectDisposedException("RegionFile", "Attempting to use a RegionFile after it has been disposed."); + } + if (OutOfBounds(x, z)) { Debugln("READ", x, z, "out of bounds"); return null; @@ -322,6 +330,10 @@ namespace Substrate.Core /* write a chunk at (x,z) with length bytes of data to disk */ protected void Write(int x, int z, byte[] data, int length, int timestamp) { + if (_disposed) { + throw new ObjectDisposedException("RegionFile", "Attempting to use a RegionFile after it has been disposed."); + } + try { int offset = GetOffset(x, z); int sectorNumber = offset >> 8; diff --git a/SubstrateCS/Source/Region.cs b/SubstrateCS/Source/Region.cs index 2ccd29c..be120cd 100644 --- a/SubstrateCS/Source/Region.cs +++ b/SubstrateCS/Source/Region.cs @@ -509,6 +509,7 @@ namespace Substrate if (ChunkCount() == 0) { _regionMan.DeleteRegion(X, Z); + _regionFile.Target = null; } return true;