WiiU: Properly handle out of memory for textures

This commit is contained in:
UnknownShadow200 2024-05-01 20:31:19 +10:00
parent 91e16cabff
commit f2307da83a

View file

@ -85,7 +85,9 @@ static void Gfx_RestoreState(void) {
static GX2Texture* pendingTex;
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
GX2Texture* tex = Mem_AllocCleared(1, sizeof(GX2Texture), "GX2 texture");
GX2Texture* tex = Mem_TryAllocCleared(1, sizeof(GX2Texture));
if (!tex) return NULL;
// TODO handle out of memory better
int width = bmp->width, height = bmp->height;
tex->surface.width = width;
@ -98,8 +100,9 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8
tex->compMap = GX2_COMP_MAP(GX2_SQ_SEL_R, GX2_SQ_SEL_G, GX2_SQ_SEL_B, GX2_SQ_SEL_A);
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
GX2InitTextureRegs(tex);
tex->surface.image = MEMAllocFromDefaultHeapEx(tex->surface.imageSize, tex->surface.alignment);
// TODO check result
if (!tex->surface.image) { Mem_Free(tex); return NULL; }
CopyTextureData(tex->surface.image, tex->surface.pitch << 2, bmp, rowWidth << 2);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, tex->surface.image, tex->surface.imageSize);
@ -430,12 +433,18 @@ void Gfx_ClearBuffers(GfxBuffers buffers) {
}
}
static int drc_ticks;
void Gfx_EndFrame(void) {
GX2ColorBuffer* buf;
buf = WHBGfxGetTVColourBuffer();
GX2CopyColorBufferToScanBuffer(buf, GX2_SCAN_TARGET_TV);
GX2ContextState* state = WHBGfxGetDRCContextState();
GX2SetContextState(state);
drc_ticks = (drc_ticks + 1) % 200;
buf = WHBGfxGetDRCColourBuffer();
GX2ClearColor(buf, drc_ticks / 200.0f, drc_ticks / 200.0f, drc_ticks / 200.0f, 1.0f);
GX2CopyColorBufferToScanBuffer(buf, GX2_SCAN_TARGET_DRC);
GX2SwapScanBuffers();