Don't crash if out of memory when allocating samples for writing .wav file

This commit is contained in:
UnknownShadow200 2020-07-14 21:48:30 +10:00
parent d403ba6659
commit a819ca770f
2 changed files with 7 additions and 3 deletions

View File

@ -111,7 +111,8 @@ void Logger_SysWarn(cc_result res, const char* place, Logger_DescribeError descr
String msg; char msgBuffer[256];
String_InitArray(msg, msgBuffer);
String_Format2(&msg, "Error %i when %c", &res, place);
String_Format2(&msg, res < 20000 ? "Error %i when %c" : "Error %h when %c",
&res, place);
AppendErrorDesc(&msg, res, describeErr);
Logger_WarnFunc(&msg);
}
@ -120,7 +121,8 @@ void Logger_SysWarn2(cc_result res, const char* place, const String* path, Logge
String msg; char msgBuffer[256];
String_InitArray(msg, msgBuffer);
String_Format3(&msg, "Error %h when %c '%s'", &res, place, path);
String_Format3(&msg, res < 20000 ? "Error %i when %c '%s'" : "Error %h when %c '%s'",
&res, place, path);
AppendErrorDesc(&msg, res, describeErr);
Logger_WarnFunc(&msg);
}

View File

@ -647,7 +647,9 @@ static void SoundPatcher_WriteWav(struct Stream* s, struct VorbisState* ctx) {
res = Vorbis_DecodeHeaders(ctx);
if (res) { Logger_Warn(res, "decoding .ogg header"); return; }
samples = (cc_int16*)Mem_Alloc(ctx->blockSizes[1] * ctx->channels, 2, ".ogg samples");
samples = (cc_int16*)Mem_TryAlloc(ctx->blockSizes[1] * ctx->channels, 2);
if (!samples) { Logger_Warn(ERR_OUT_OF_MEMORY, "allocating .ogg samples"); return; }
for (;;) {
res = Vorbis_DecodeFrame(ctx);