From aadb7172a9e2c1d903238333fe7f94de64128988 Mon Sep 17 00:00:00 2001 From: JuiceyDev Date: Fri, 6 Mar 2026 11:27:47 +0100 Subject: [PATCH] buffer fix --- .../IO/Streams/BufferedOutputStream.cpp | 17 ++++++++++++++-- .../IO/Streams/DataOutputStream.cpp | 20 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Minecraft.World/IO/Streams/BufferedOutputStream.cpp b/Minecraft.World/IO/Streams/BufferedOutputStream.cpp index 7c9ba0dcd..2c56649b6 100644 --- a/Minecraft.World/IO/Streams/BufferedOutputStream.cpp +++ b/Minecraft.World/IO/Streams/BufferedOutputStream.cpp @@ -21,9 +21,17 @@ BufferedOutputStream::~BufferedOutputStream() //Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream. void BufferedOutputStream::flush() { - stream->write( buf, 0, count ); + if (stream == NULL) + { + app.DebugPrintf("BufferedOutputStream::flush() called but underlying stream is NULL\n"); + return; + } - count = 0; + if (count > 0) + { + stream->write( buf, 0, count ); + count = 0; + } } //Closes this output stream and releases any system resources associated with the stream. @@ -31,6 +39,11 @@ void BufferedOutputStream::flush() void BufferedOutputStream::close() { flush(); + if (stream == NULL) + { + app.DebugPrintf("BufferedOutputStream::close() called but underlying stream is NULL\n"); + return; + } stream->close(); } diff --git a/Minecraft.World/IO/Streams/DataOutputStream.cpp b/Minecraft.World/IO/Streams/DataOutputStream.cpp index f7e9585b2..ae4d7aa24 100644 --- a/Minecraft.World/IO/Streams/DataOutputStream.cpp +++ b/Minecraft.World/IO/Streams/DataOutputStream.cpp @@ -24,6 +24,11 @@ void DataOutputStream::deleteChildStream() //b - the byte to be written. void DataOutputStream::write(unsigned int b) { + if (stream == NULL) + { + app.DebugPrintf("DataOutputStream::write(unsigned int) called but underlying stream is NULL\n"); + return; + } stream->write( b ); // TODO 4J Stu - Exception handling? written++; @@ -31,6 +36,11 @@ void DataOutputStream::write(unsigned int b) void DataOutputStream::flush() { + if (stream == NULL) + { + app.DebugPrintf("DataOutputStream::flush() called but underlying stream is NULL\n"); + return; + } stream->flush(); } @@ -51,6 +61,11 @@ void DataOutputStream::write(byteArray b) //len - the number of bytes to write. void DataOutputStream::write(byteArray b, unsigned int offset, unsigned int length) { + if (stream == NULL) + { + app.DebugPrintf("DataOutputStream::write(byteArray,...) called but underlying stream is NULL\n"); + return; + } stream->write(b, offset, length); // TODO 4J Stu - Some form of error checking? written += length; @@ -60,6 +75,11 @@ void DataOutputStream::write(byteArray b, unsigned int offset, unsigned int leng //The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream. void DataOutputStream::close() { + if (stream == NULL) + { + app.DebugPrintf("DataOutputStream::close() called but underlying stream is NULL\n"); + return; + } stream->close(); }