dmBuffer::Create() crash (DEF-3761)


Looks like dmBuffer::Create()is not thread safe. Sometimes it crashes in my recent extension

And only during app start. Haven’t seen this when the app has successfully launched.

Assertion failed: (ctx->m_Buffers[index] == 0), function SetBuffer, file ../src/dlib/buffer.cpp, line 125.

Here is crash report dmbuffer_crash.lua (60.4 KB)

What can I do about that?


I’ll let @Mathias_Westerdahl or @sven answer this.


Probably the same, Lua isn’t thread safe :


It’s similar stuff. I already don’t invoke Lua stuff on a thread, when I am invoking a callback, I do so on the main thread inside the update function.
But Defold’s internal stuff can be accessed in other threads, it’s just some things are not thread safe. Here I am creating a new buffer object at the same time when the engine creates other buffer objects.

if I could set up a mutex or precreate the buffer object on the main thread, that would solve the problem. But mutex has to be incorporated in the engine and I can’t easily precreate the buffer object, because it needs buffer size value, and I know the size only inside the thread when image is being loaded.

So if there is a way to resize the buffer object after creation, that would solve the issue. Or maybe there is some other smart solution. If not, I will have to rework my threading code to invoke dmBuffer::Create() on the main thread.


Yes, looking at the code, it seems the code isn’t thread safe. There is no real reason why it shouldn’t be.
I’ve added DEF-3761 for this.


Awesome, thanks!