Fixed crash in djui_gfx_render_texture_tile()

This commit is contained in:
MysterD 2023-04-24 01:16:54 -07:00
parent 07324c5396
commit 5113e9e99c

View file

@ -7,6 +7,7 @@
#include "src/pc/gfx/gfx_window_manager_api.h"
#include "gfx_dimensions.h"
#include "djui_gfx.h"
#include "pc/debuglog.h"
const Gfx dl_djui_display_list_begin[] = {
gsSPTextureAddrDjui(1),
@ -102,7 +103,22 @@ void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize) {
}
void djui_gfx_render_texture_tile(const u8* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH) {
if (!gDisplayListHead) {
LOG_ERROR("Retrieved a null displaylist head");
return;
}
if (!texture) {
LOG_ERROR("Attempted to render null texture");
return;
}
Vtx *vtx = alloc_display_list(sizeof(Vtx) * 4);
if (!vtx) {
LOG_ERROR("Failed to allocate vertices");
return;
}
f32 aspect = tileH ? ((f32)tileW / (f32)tileH) : 1;
// I don't know why adding 1 to all of the UVs seems to fix rendering, but it does...
vtx[0] = (Vtx) {{{ 0, -1, 0 }, 0, { ( tileX * 512) / w + 1, ((tileY + tileH) * 512) / h }, { 0xff, 0xff, 0xff, 0xff }}};