Fixed region object bug when deleting last chunk in region

This commit is contained in:
Justin Aquadro 2012-02-20 16:30:54 -05:00
parent 02691712f9
commit 33e8cf2174
2 changed files with 13 additions and 0 deletions

View file

@ -69,6 +69,10 @@ namespace Substrate.Core
protected void ReadFile () protected void ReadFile ()
{ {
if (_disposed) {
throw new ObjectDisposedException("RegionFile", "Attempting to use a RegionFile after it has been disposed.");
}
// Get last udpate time // Get last udpate time
long newModified = -1; long newModified = -1;
try { try {
@ -201,6 +205,10 @@ namespace Substrate.Core
* the chunk is not found or an error occurs * the chunk is not found or an error occurs
*/ */
public Stream GetChunkDataInputStream(int x, int z) { 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)) { if (OutOfBounds(x, z)) {
Debugln("READ", x, z, "out of bounds"); Debugln("READ", x, z, "out of bounds");
return null; return null;
@ -322,6 +330,10 @@ namespace Substrate.Core
/* write a chunk at (x,z) with length bytes of data to disk */ /* 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) { 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 { try {
int offset = GetOffset(x, z); int offset = GetOffset(x, z);
int sectorNumber = offset >> 8; int sectorNumber = offset >> 8;

View file

@ -509,6 +509,7 @@ namespace Substrate
if (ChunkCount() == 0) { if (ChunkCount() == 0) {
_regionMan.DeleteRegion(X, Z); _regionMan.DeleteRegion(X, Z);
_regionFile.Target = null;
} }
return true; return true;