Buffer stride can not be smaller than the size of a single item;

This commit is contained in:
bjorn 2022-04-28 15:39:45 -07:00
parent a8b7bc75a8
commit a97193caac
2 changed files with 8 additions and 3 deletions

View File

@ -156,6 +156,7 @@ static void luax_checkbufferformat(lua_State* L, int index, BufferInfo* info) {
lovrAssert(info->fieldCount <= COUNTOF(info->fields), "Too many buffer fields (max is %d)", COUNTOF(info->fields));
uint32_t offset = 0;
uint32_t extent = 0;
uint32_t location = 0;
uint32_t maxAlign = 1;
for (int i = 0; i < length; i++) {
@ -192,6 +193,8 @@ static void luax_checkbufferformat(lua_State* L, int index, BufferInfo* info) {
maxAlign = MAX(maxAlign, align);
}
lua_pop(L, 1);
extent = MAX(extent, field->offset + fieldInfo[field->type].size);
}
lua_getfield(L, index, "stride");
@ -203,7 +206,9 @@ static void luax_checkbufferformat(lua_State* L, int index, BufferInfo* info) {
default: break;
}
} else {
info->stride = luaL_checkinteger(L, -1);
info->stride = luax_checku32(L, -1);
lovrCheck(info->stride > 0, "Buffer stride can not be zero");
lovrCheck(info->stride <= extent, "Buffer stride can not be smaller than the size of a single item");
}
lua_pop(L, 1);
break;

View File

@ -123,7 +123,7 @@ void lovrGraphicsGetLimits(GraphicsLimits* limits) {
// Buffer
Buffer* lovrGraphicsGetBuffer(BufferInfo* info, void** data) {
uint32_t size = info->length * MAX(info->stride, 1);
uint32_t size = info->length * info->stride;
lovrCheck(size > 0, "Buffer size can not be zero");
lovrCheck(size <= 1 << 30, "Max buffer size is 16GB");
@ -143,7 +143,7 @@ Buffer* lovrGraphicsGetBuffer(BufferInfo* info, void** data) {
}
Buffer* lovrBufferCreate(BufferInfo* info, void** data) {
uint32_t size = info->length * MAX(info->stride, 1);
uint32_t size = info->length * info->stride;
lovrCheck(size > 0, "Buffer size can not be zero");
lovrCheck(size <= 1 << 30, "Max buffer size is 1GB");