From bded15ff2a67cda2cbf01669d0264d028a6d563a Mon Sep 17 00:00:00 2001 From: slime Date: Thu, 25 Aug 2022 19:44:10 -0300 Subject: [PATCH] Decoders failing to allocate their buffer will cause a Lua error instead of crashing. --- src/modules/sound/Decoder.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/sound/Decoder.cpp b/src/modules/sound/Decoder.cpp index 355b783c9..9b8923db6 100644 --- a/src/modules/sound/Decoder.cpp +++ b/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()