Unknown crash bug of my code

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
r3v3n93
Posts: 35
Joined: Tue Jun 09, 2020 7:16 am
Graphics Processor: nVidia (Modern GZDoom)
Location: North Korea

Unknown crash bug of my code

Post by r3v3n93 »

Code: Select all

virtual state A_SCLook() //called in "Spawn"
	{
		A_Look();
		if(CheckProximity("Doomplayer", 1000, 1, CPXF_SETMASTER) && !target)
		{
			A_Log("I set my master, and Im following him");
			target = master;
			return ResolveState("SeeFriend"); //when the actor acquires player, it'll set the player to target and will send to this special See state. Not associated with the bug. I tested it.
		}	
		return State(null);	
	}
	
virtual State A_SCChase(bool is_melee_state_there = false) /called in "See"
	{
		A_Log("Hi, I'm new to A_SCChase.");
		if(!target)
		{
			return ResolveState("Spawn");
		} //For some reason, sending the actor to Spawn state from Pain state when the actor is following the player crashes. It's either this block's problem or the A_SCLook's Problem
		if(target && master)
		{
			if((target == master))
			{
				A_Log("Im Chasing");
				return ResolveState("Seefriend");
			}
			else if(target != master)
			{
				A_Log("Trying to pursuit enemy.");
			}
		}
		
		A_Log("TEST");
		bSTANDSTILL = false;

		//A_LookEX(0, 1, MaxTargetRange, MaxTargetRange, 360, "Missile");
		
		if(is_melee_state_there == true && Distance2D(target) <= MeleeRange && target)
		{
			return ResolveState("melee");
		}

		if(target && Distance2D(target) <= MaxTargetRange)
		{
			return ResolveState("Missile");
		}
		
		A_FaceTarget();
		NewChaseDir();
		return State(null);	
	}	
	
Pain:
    	PLAY G 4
		{
			if(target)
			{
				if(master)
				{
					if(target == master) //when the actor is following the player...
					{
						A_Log("I cleared my target");
						A_ClearTarget();
					}
				}
			}	
		}
    	PLAY G 4;
    	Goto See;	
	
This actor is a friendly monster and has an algorithm to follow player whenever they don't have hostile targets. If the actor gets hurt, if the actor is following the player, it will clear the pointer in where the player was defined for compatibility with See state.
Here's the issue. When player attacks the actor on purpose when the actor is following the player, the game just crashes without any crash logs. Any solutions?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Unknown crash bug of my code

Post by Player701 »

Your code cannot be run as-is. Please provide a runnable example for testing. As of now, I cannot be certain, but it looks like you may be triggering a condition where your code starts jumping back and forth between two states continuously and without any delay between the jumps. Or it could be a stack overflow - these are the two most common scenarios that GZDoom is not able to handle gracefully.
Post Reply

Return to “Scripting”