0

If a script uses ffi.metatype and crashes unexpectedly,the next script startup produces this error : “cannot change a protected metatable”,this makes debugging real hard as I have to restart my game each time,any way to circumvent this?

Here’s a test script that demonstrates this issue,make sure to run it twice.

ffi.cdef[[
        typedef struct {
            float x,y;

        } Crash;
]]

local Crash_Metatype = ffi.metatype("Crash",{})

print(x + y)

1 Answers1

0

You can't call ffi.metatype on the same C type twice. Either set a variable after doing so and don't do so again if it's already set, or wrap the call to it in pcall so you can ignore that error.

  • I'm not calling it twice,because the script crashes the first time,the second time I start the script,ffi.metatype fails probably because the definition still exists in memory from the first time I ran the script,I tried the pcall method and it doesn't work.Oh and I should probably mention that this issue doesn't occur if the script doesn't crash the first time. – Syahmi Zul Jan 08 '23 at 09:01