Browse Source

Decoders failing to allocate their buffer will cause a Lua error instead of crashing.

slime 3 years ago
parent
commit
bded15ff2a
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/modules/sound/Decoder.cpp

+ 8 - 1
src/modules/sound/Decoder.cpp

@@ -39,7 +39,14 @@ Decoder::Decoder(Stream *stream, int bufferSize)
 	if (!stream->isReadable() || !stream->isSeekable())
 		throw love::Exception("Decoder input stream must be readable and seekable.");
 
-	buffer = new char[bufferSize];
+	try
+	{
+		buffer = new char[bufferSize];
+	}
+	catch (std::exception &)
+	{
+		throw love::Exception("Out of memory.");
+	}
 }
 
 Decoder::~Decoder()