lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Sean Conner once stated:
> It was thus said that the Great John Dunn once stated:
> > >  If you are using Linux, could you run the app under valgrind?  It will
> > >  take longer, but it should reveal some issues.
> > 
> > Running on Ubuntu using g++ 9.3.0 it is still crashing. Here is the output
> > of valgrind. It definitely detected an error - the issue for me is that's
> > the error is deep inside of Lua and I'm not sure how my code could have
> > caused this. This is using Lua 5.3 from apt-get so it doesn't contain any
> > modifications.
> 
>   I went back to the original example you provided, recompiled it, and yes,
> I finally got a segfault.  Using valgrind, I was able to find the problem in
> this function:
> 
> 	struct mytimer
> 	{
> 	  lua_State* L;
> 	  int handler_index{ LUA_REFNIL };
> 	  void trigger()
> 	  {
> 	    std::cout << __FUNCTION__ << std::endl;
> 	    lua_rawgeti(L, LUA_REGISTRYINDEX, handler_index);
> 	    lua_pcall(L, 0, 0, 0);
> 	  }
> 	};

  Furthermore, I changed the code a bit to print out the Lua pointer when
created, and when used in trigger() and timer_after_call().  The output from
that run:

	[spc]matrix:~/tmp>./co11
	running good code
	L new state 0x558e8fe4a2c8
	init good
	timer_call_after L state param 0x558e8fe4a2c8
	init good
	trigger L state param 0x558e8fe4a2c8
	trigger L state 0x558e8fe4a2c8
	tick
	running bad code
	L new state 0x558e8fe510a8
	timer_call_after L state param 0x558e8fe58108
	init good
	trigger L state param 0x558e8fe510a8
	trigger L state 0x558e8fe58108

  So Xmilia Hermit's reply is correct about the Lua states.  

  -spc