[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C api calling cause crash, critical issue
- From: Peter Cawley <lua@...>
- Date: Tue, 9 Mar 2010 12:16:56 +0000
On Tue, Mar 9, 2010 at 10:53 AM, sagasw <sagasw@gmail.com> wrote:
> for(int i = 0; i < 500; i++)
> {
> printf("%d\n", i);
> loadfile1(LA);
> }
> ...
> bool loadfile1(lua_State* LA)
> {
> if(!LA)
> return false;
>
> lua_State* LB = lua_newthread(LA);
> return true;
> }
lua_newthread(LA) will leave the created thread on LA's stack, so your
for loop pushes 500 elements onto the Lua stack. If you ever want to
use more than 20 stack slots, you must call lua_checkstack to ensure
that enough stack slots are allocated. Otherwise, you'll be writing
beyond the end of the stack array, causing bad things like random
crashes.