Jump to content
  • Advertisement
Sign in to follow this  

Again some lua issues

This topic is 3762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm shure I'm doing something wrong here. Basicly, I've got this function, that is being executed every frame by every monster:
int CMonster::_GetListOfNPCs( lua_State *L )
	if( lua_gettop( L ) != 1 ) {
		lua_pushstring( L, "Incorrect argument to 'GetListOfMonsters'" );
		lua_error( L );

	if( !lua_isnumber( L, 1 ) )
		lib::lua::typerror( L, 1, "number" );

	float radius = static_cast<float>( lua_tonumber( L, 1 ) );
	std::vector<CNPC*> npcs;

	SGElements *pArray = m_pParent->GetChildArray();
	foreach( CSGNode *pNode, *pArray )
		if( (pNPC = dynamic_cast<CNPC*>( pNode ) ) )
			if( pNPC->GetDead() )

			C3DVector dist = m_Position - pNPC->GetPosition();
			if( dist.length() <= radius )
				npcs.push_back( pNPC );

	//lua_newtable( L );
	//int table = lua_gettop( L );

	/*UINT i = 0;
	foreach( CNPC *pNPC, npcs )
		lua_pushnumber( L, i ); // Index
		CNPC::push( L, pNPC, false ); // Value
		lua_settable( L, table ); // Does Table[Index] = Value


	return 0;

The commented code does NOT work at all. It goes like this: The code runs 1 time (I only have 1 monster so far) and the second time I get an exception by my runtime library:
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.

When I follow the call stack I notice that the crash happens during the garbage collection of lua. I believe this assertion happens the second frame, because the gc doesn't trigger the first time, because the lua stack is not big enough to be cleaned up, however this is speculation. I only get this assertion in debug mode and only if I uncomment the above line, containing lua_newtable...). I need to add that the npcs array is totaly empty when this happens: the code in the foreach loop doesn't get executed. Ofcourse the function returns 1 when lua_newtable is uncommented. I just switched to 0, because my function doesn't return anything (to not cause a crash). I'm really stuck here, any help is appreciated :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!