View Single Post
Re: SWDS.dll Crashes.
Old
  (#6)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: SWDS.dll Crashes. - 19-08-2004

theory:

If you are calling CBaseEntity methods through a pointer you got from your create function it could be accessing the wrong area of memory i.e. if you casted it wrong and called a method, the method locations will be in the wrong place and execution could wander through lines of code which manipulates the call stack and leaving it in an inconsistant state... (if by calling a method it took code into the middle of a function, it would not push the stack but would pop it at the end)

in short:

I'm guessing you are casting the values returned by your create function from edict_t* to CBaseEntity*

The thing I believe is that to cast an edict_t* to a CBaseEntity* you must cast it by it's privateData and not the edict_t* memory location. i.e. by:

CBaseEntity *pEnt = (CBaseEntity*)GET_PRIVATE(pEdict);

To help you, here is code from my "marine build" function from my bot, which I am also guessing you are using natural-selection. My code works okay when spawning structures in Natural-selection, even resource towers but they don't give resources to the marines (at least that doesn't crash though, i found why it crashes in that case)

have a look if you wish:

Code:
//
// Hack building
edict_t *BotFunc_NS_MarineBuild ( int iUser3, const char *szClassname, Vector vOrigin, edict_t *pEntityUser )
{
	edict_t *build = NULL;//pfnCreateNamedEntity(MAKE_STRING(pCommBuildent));

	edict_t *pSetgroundentity = NULL;


	if ( iUser3 == AVH_USER3_RESTOWER )
	{
		// find nearest struct resource fountain
		char *classname[1] = {"func_resource"};
		
		edict_t *pResource = UTIL_FindNearestEntity(classname,1,vOrigin,200,FALSE);
		
		if ( pResource )
		{
			if ( UTIL_IsResourceFountainUsed(pResource) )
			{
				BotMessage(pEntityUser,0,"Error: Nearest resource fountain is used");
				return NULL;
			}

			pSetgroundentity = pResource;
			vOrigin = pResource->v.origin+Vector(0,0,1);
		}
		else
		{
			BotMessage(pEntityUser,0,"Error: Can't find a resource fountain for tower");
			return NULL;
		}
	}

	build = CREATE_NAMED_ENTITY(MAKE_STRING(szClassname));
	
	if ( build && !FNullEnt(build) )
	{
		if ( pSetgroundentity )
			build->v.groundentity = pSetgroundentity;

		SET_ORIGIN(build,vOrigin);			
		
		build->v.iuser3 = iUser3;
		
		if ( iUser3 != AVH_USER3_MARINEITEM )			
		{
			build->v.iuser4 = MASK_BUILDABLE | MASK_SELECTABLE;
		}
		else
			build->v.iuser4 = MASK_NONE;
		
		build->v.takedamage = 1;
		build->v.movetype = 6;
		build->v.solid = 2;
		build->v.team = 1;
		build->v.flags = 544;
		
		build->v.nextthink = gpGlobals->time + 0.1;

#ifdef RCBOT_META_BUILD
		MDLL_Spawn(build);
#else
		DispatchSpawn(build);
#endif

		return build;
	}

	return NULL;
}
[/code]
  
Reply With Quote