Jump to content
sarogahtyp

[Solved] Spawning a Vehicle - Access Violation

Recommended Posts

Hey,

I get a Crash to Desktop because of an Access Violation when I am trying to spawn a Hum-Vee.

This is my user action class which PerformAction method is executed when the player uses the proper action of the related action menu:

Spoiler

class SaRo_BMHQDeliverVehicle : SaRo_BMHQMenuBaseClass
{
	//------------------------------------------------------------------------------------------------
	override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
	{
	
		//prepare resource for spawning using prefabs resource name
		Resource resourceArmedHumvee = Resource.Load ("{DD774A8FD0989A78}Prefabs/Vehicles/Wheeled/M998/M1025_armed_M2HB_MERDC.et");
		
		//spawn params object creation
		EntitySpawnParams paramsArmedHumvee = new EntitySpawnParams();

		
		//get spawn location somwhere behind user entity
	    vector spawnPosition = pUserEntity.VectorToParent( Vector (0, 0, -5) );
		
		//assign spawn position to params object
		paramsArmedHumvee.Transform[3] = spawnPosition;
		
		// spawn Hum-Vee using already prepared prefab resource and  params object
		IEntity armedHumvee = Game().SpawnEntityPrefab(resourceArmedHumvee, null, paramsArmedHumvee);

		SCR_HintManagerComponent.GetInstance().ShowCustomHint("Your vehicle which gets you fast into combat zone is delivered already.", "Vehicle Delivery", 3.0);
	}

	//------------------------------------------------------------------------------------------------
	override void CancelAction(IEntity pUserEntity)
	{
	}
	
	//------------------------------------------------------------------------------------------------
	override bool CanBeShownScript(IEntity user)
	{
		if (SaRo_BMHQMenuBaseClass.SaRo_BMHQisBuild) return true;
		else return false;
	}

	//------------------------------------------------------------------------------------------------
	override bool CanBePerformedScript(IEntity user)
	{
		if (SaRo_BMHQMenuBaseClass.SaRo_BMHQisBuild) return true;
		else return false;
	}

	//------------------------------------------------------------------------------------------------
	override bool HasLocalEffectOnlyScript()
	{
		return true;
	}
};

 

 

 

This line is causing the access violation error:

// spawn Hum-Vee using already prepared prefab resource and  params object
IEntity armedHumvee = Game().SpawnEntityPrefab(resourceArmedHumvee, null, paramsArmedHumvee);

if I comment it out then the method works fine. Otherwise its crashing the workbench.

Idk what could cause the crash here...

Any help will be appreciated.

Share this post


Link to post
Share on other sites

Problem is solved.

The crash was caused by using Game().SpawnEntityPrefab(...) instead of GetGame().SpawnEntityPrefab(...).

I modified more things meanwhile but using GetGame() solved the crash issue:

Spoiler

class SaRo_BMHQDeliverVehicle : SaRo_BMHQMenuBaseClass
{
	//------------------------------------------------------------------------------------------------
	override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
	{
	
		//prepare resource for spawning using prefabs resource name
		Resource resourceArmedHumvee = Resource.Load ("{DD774A8FD0989A78}Prefabs/Vehicles/Wheeled/M998/M1025_armed_M2HB_MERDC.et");
		
		//get source by resource
		IEntitySource sourceArmedHumvee = SCR_BaseContainerTools.FindEntitySource(resourceArmedHumvee);
		
		//spawn params object creation
		EntitySpawnParams paramsArmedHumvee = new EntitySpawnParams();

		//get spawn location somwhere behind user entity
	    vector spawnPosition = pUserEntity.CoordToParent( Vector (0, 0, -15) );
		
		//assign spawn position to params object
		paramsArmedHumvee.Transform[3] = spawnPosition;
		
		//snap spawn position to ground
		SCR_Global.SnapToTerrain(paramsArmedHumvee.Transform, GetGame().GetWorld(), true);
		
		float scaleArmedHumvee;
		
		sourceArmedHumvee.Get("scale", scaleArmedHumvee);
		
		if ( scaleArmedHumvee != 1.0) SCR_Math3D.ScaleMatrix (paramsArmedHumvee.Transform, scaleArmedHumvee);		
		
		// spawn Hum-Vee using already prepared prefab resource and  params object
		IEntity armedHumvee = GetGame().SpawnEntityPrefab(resourceArmedHumvee, GetGame().GetWorld(), paramsArmedHumvee);

		SCR_HintManagerComponent.GetInstance().ShowCustomHint("Your vehicle which gets you fast into combat zone is delivered already.", "Vehicle Delivery", 3.0);
	}

	//------------------------------------------------------------------------------------------------
	override void CancelAction(IEntity pUserEntity)
	{
	}
	
	//------------------------------------------------------------------------------------------------
	override bool CanBeShownScript(IEntity user)
	{
		if (SaRo_BMHQMenuBaseClass.SaRo_BMHQisBuild) return true;
		else return false;
	}

	//------------------------------------------------------------------------------------------------
	override bool CanBePerformedScript(IEntity user)
	{
		if (SaRo_BMHQMenuBaseClass.SaRo_BMHQisBuild) return true;
		else return false;
	}

	//------------------------------------------------------------------------------------------------
	override bool HasLocalEffectOnlyScript()
	{
		return true;
	}
};

 

 

Thx to Aaron Static#4717 who solved my issue on discord 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×