Game Development Community

"Cannot access memory at address 0x10"... need some advice

by Dave Calabrese · in iTorque 2D · 05/22/2009 (5:02 pm) · 1 replies

Recently, I started receiving this error whenever going to run our game:

"Cannot access memory at address 0x10"

I've tracked it down to one line of code in the Script where we add the component to the behavior. I've marked it below...


function NinjaEnemyBehavior::onBehaviorAdd(%this)
{
   // Create the Component
   %this.Component = new NinjaEnemyComponent();

   // let other scripts reference to us
   %this.Owner.NinjaEnemyComponent = %this.Component;

   // IMPORTANT, this copies you behavior fields to their matching component fields
   copyBehaviorToComponent(%this, %this.Component);

   // Add the component
   if (!%this.Owner.addComponents(%this.Component))  //<------------ THIS MAKES IT CRASH
   {
      error ("NinjaEnemyComponent::onBehaviorAdd - Failed to register NinjaEnemyComponent Component");
      %this.Component.safeDelete();
      return;
   }
}

So I went back into the engine code, and started commenting things out, searching around, and I'm not sure really why this is crashing. Here is what it looks like on the engine side:
bool ninjaEnemyComponent::onComponentAdd(SimComponent *target)
{
	if (!Parent::onComponentAdd(target))
		return false;
	
	
	t2dSceneObject *owner = dynamic_cast<t2dSceneObject*>(target);
	if (!owner)
	{
		Con::warnf("ninjaEnemyComponent::onComponentAdd - Must be added to a t2dSceneObject.");
		return false;
	}
	
	// Store our owner
	mOwner = owner;
	
	// Determine if this enemy will always try and be on the left or right side of the player.
	if( (rand()%10)+1 > 6 )
		mLeftOrRight = false;
	else
		mLeftOrRight = true;
	
	if( !mObjectName ) {
		Con::errorf( "ninjaEnemyComponent has no object to follow" );
	}
	
	return true;
}

If I change the last line to "return false", then the crash does not occur and the game runs. So something about returning true makes it unable to read an address in memory. Anyone have any suggestions on where to look or what to look at to fix this problem?