Don't crash if out of memory reallocating data for freetype or allocating output buffer for music

This commit is contained in:
UnknownShadow200 2020-02-27 15:45:53 +11:00
parent 23ee71914f
commit 56d20790ce
3 changed files with 4 additions and 3 deletions

View File

@ -767,7 +767,9 @@ static cc_result Music_PlayOgg(struct Stream* source) {
/* so we may end up decoding slightly over a second of audio */
chunkSize = fmt.channels * (fmt.sampleRate + vorbis.blockSizes[1]);
samplesPerSecond = fmt.channels * fmt.sampleRate;
data = (cc_int16*)Mem_Alloc(chunkSize * AUDIO_MAX_BUFFERS, 2, "Ogg final output");
data = (cc_int16*)Mem_TryAlloc(chunkSize * AUDIO_MAX_BUFFERS, 2);
if (!data) { res = ERR_OUT_OF_MEMORY; goto cleanup; }
/* fill up with some samples before playing */
for (i = 0; i < AUDIO_MAX_BUFFERS && !res; i++) {

View File

@ -875,7 +875,7 @@ static cc_result SysFont_Init(const String* path, struct SysFont* font, FT_Open_
static void* FT_AllocWrapper(FT_Memory memory, long size) { return Mem_TryAlloc(size, 1); }
static void FT_FreeWrapper(FT_Memory memory, void* block) { Mem_Free(block); }
static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, void* block) {
return Mem_Realloc(block, new_size, 1, "Freetype data");
return Mem_TryRealloc(block, new_size, 1);
}
static cc_bool updatedSysFonts;

View File

@ -1,6 +1,5 @@
#ifndef CC_GFXAPI_H
#define CC_GFXAPI_H
#include "PackedCol.h"
#include "Vectors.h"
#include "GameStructs.h"
#include "Bitmap.h"