mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Fix crashes when creating a Buffer.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user