[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: coroutine.resume() crash
- From: Sean Conner <sean@...>
- Date: Thu, 8 Sep 2022 17:30:32 -0400
It was thus said that the Great John Dunn once stated:
> I am using Lua 5.3.2 and have some Lua modules that implement asynchronous
> callbacks. I was trying to wrap them in coroutines to make them act a
> little more like async/await and when I do that I get a crash
>
> ldo:636
> Exception thrown: read access violation
> ci->u.l.base was 0xFFFFFFFFFFFFFFFF
>
> Here's example code that shows the problem - it crashes when running
> 'bad_lua'. Am I just misunderstanding how coroutines can operate?
I was unable to reproduce the issue with Lua 5.3.2. I did, however, have
some issues with compiling your code using G++ 11.2.0 under Linux (with the
latest version of Ubuntu).
> #include <string>
Ths needs to be <cstring>.
> struct timer_t
> {
...
> };
The compiler complained that timer_t was already defined in a system
header. I changed it from 'struct timer_t' to 'struct mytimer'.
> void timer_init(lua_State* L)
> {
> luaL_register(L, "Timer", timer_lib_methods);
> }
The function luaL_register() isn't defined for Lua 5.3.2 (although you
might have headers that include some compatability macros for it). This was
an easy change:
void timer_init(lua_State* L)
{
luaL_newlib(L,timer_lib_methods);
lua_setglobal(L,"Timer");
}
With those changes, the code compled and when run, I got:
[spc]matrix:/tmp>./co
running good code
init good
timer_call_after
init good
trigger
tick
running bad code
trigger
tick
I won't claim a compiler bug just yet---it might be caused by issues I
outlined here. It might also help with knowing the operating system and
compiler you saw the error with.
-spc