Skip to content

Commit 6f1d004

Browse files
committed
Fix crash when writing buffers with nested structs;
1 parent 5930639 commit 6f1d004

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/api/l_graphics.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ static uint32_t luax_checkbufferformat(lua_State* L, int index, DataField* field
590590
lua_getfield(L, -1, "type");
591591
if (lua_isnil(L, -1)) lua_pop(L, 1), lua_rawgeti(L, -1, 2);
592592
if (lua_istable(L, -1)) {
593+
field->type = ~0u;
593594
field->fields = fields + *count;
594595
field->fieldCount = luax_checkbufferformat(L, -1, fields, count, max);
595596
} else if (lua_type(L, -1) == LUA_TSTRING) {

src/api/l_graphics_buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static void luax_checkstruct(lua_State* L, int index, const DataField* structure
251251

252252
if (lua_isnil(L, -1)) {
253253
memset(data + field->offset, 0, MAX(field->length, 1) * field->stride);
254-
} else if (typeComponents[field->type] > 1 && lua_type(L, -1) == LUA_TNUMBER) {
254+
} else if (field->length == 0 && field->fieldCount == 0 && typeComponents[field->type] > 1 && lua_type(L, -1) == LUA_TNUMBER) {
255255
// Need to special case situation where number is provided for vector field,
256256
// luax_checkbufferdata doesn't handle this properly
257257
int n = typeComponents[field->type];

0 commit comments

Comments
 (0)