lua-users home
lua-l archive

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

Actually, i just un-patched the lua, so it's back to lua5.1w6 instead of cumulative and it works!

Mike Pall wrote:


David Morris-Oliveros wrote:
[...] i'm getting very reproducible memory corruption
_somewhere_. This is visible in a totally corrupt stack trace
during reproducible crashes.
  ScriptInstance( lua_State* masterState ) {
      m_SubLuaState = lua_newthread( masterState );

Have a look at the docs for lua_newthread():
"This function pushes the thread on the stack and returns
a pointer to a lua_State that represents this new thread."

The first part of the sentence is there for a good reason:
the Lua GC needs to know that the coroutine is still alive,
so you need to anchor it somewhere (table, registry, globals).
If not, then Lua will happily garbage collect your coroutine
and all kinds of strange things will happen. Just holding
a pointer to it in some C structure won't do.

In your case it's probably easiest to anchor a table at the
registry (use a unique lightuserdata key based on some dummy
static variable in your C program) and add your coroutines
there (e.g. indexed by a lightuserdata key of itself). Don't
forget to remove them in the destructor.

It might be a good idea to turn on assertions in the Lua core
while you are developing, too. See luaconf.h.


// David Morris-Oliveros
// Camera & Lua Coder
// Team Bondi

Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
This email may contain confidential information.  If you are not
the intended recipient, you may not copy or deliver this message to
anyone. In such case, you should destroy this message and kindly
notify the sender by reply email. Opinions, conclusions and other
information in this message that do not relate to the official business
of our firm shall be understood as neither given nor endorsed by it.