Fix crashes when creating a Buffer.

This commit is contained in:
Alex Szpakowski
2020-07-21 20:50:49 -03:00
parent 77834d8e6c
commit c2be89f130
3 changed files with 8 additions and 6 deletions
+2
View File
@@ -91,6 +91,8 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
dataMembers.push_back(member);
}
stride = offset;
if (size != 0)
{
size_t remainder = size % stride;
+3
View File
@@ -38,6 +38,9 @@ namespace opengl
Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &format, const void *data, size_t size, size_t arraylength)
: love::graphics::Buffer(gfx, settings, format, size, arraylength)
{
size = getSize();
arraylength = getArrayLength();
if (typeFlags & TYPEFLAG_VERTEX)
mapType = BUFFERTYPE_VERTEX;
else if (typeFlags & TYPEFLAG_INDEX)
+3 -6
View File
@@ -1523,10 +1523,12 @@ int w_newIndexBuffer(lua_State *L)
size_t bytesize = 0;
DataFormat format = DATAFORMAT_UINT16;
Data *data = nullptr;
const void *initialdata = nullptr;
if (luax_istype(L, 1, Data::type))
{
data = luax_checktype<Data>(L, 1);
initialdata = data->getData();
bytesize = data->getSize();
}
@@ -1565,7 +1567,7 @@ int w_newIndexBuffer(lua_State *L)
}
Buffer *b = nullptr;
luax_catchexcept(L, [&] { b = instance()->newBuffer(settings, format, nullptr, bytesize, arraylength); });
luax_catchexcept(L, [&] { b = instance()->newBuffer(settings, format, initialdata, bytesize, arraylength); });
if (lua_istable(L, 1))
{
@@ -1584,11 +1586,6 @@ int w_newIndexBuffer(lua_State *L)
u32data[i] = (uint32) v;
}
}
else if (data != nullptr)
{
Buffer::Mapper mapper(*b);
memcpy(mapper.data, data->getData(), std::min(data->getSize(), b->getSize()));
}
luax_pushtype(L, b);
b->release();