SetStateLabel crashes when called from a static function

These bugs do plan to be resolved, when they can be.

Moderator: GZDoom Developers

User avatar
phantombeta
Posts: 2011
Joined: Thu May 02, 2013 1:27 am
Graphics Processor: nVidia with Vulkan support

SetStateLabel crashes when called from a static function

Post by phantombeta »

Vaecrius wrote:Why can I not call SetStateLabel, FindState, etc. from a static function?

This will always hard crash on startup:

Code: Select all

struct HDMobStatic play{
	static void HDA_Chase(actor self,actor movetarget=null){
		if(!self.target||self.target.health<random(-5,1)){
			self.target=null;
			self.setstatelabel("spawn");
			return;
		}
/*
		vector3 totarget=self.target.pos-self.pos;
...
*/
	}
}
For some reason, calling SetStateLabel from a static function crashes GZDoom on startup.
Here's a better example:

Code: Select all

version "2.4"

struct SSLCrashTest play {
	static void SSLCrashTestFunc (Actor act) {
		act.SetStateLabel ("Spawn");
	}
}
You don't need to actually call the function anywhere, just have it in a ZScript file.
Apparently if you change it from a struct to an actor it doesn't crash.

Even if you're not supposed to do that, GZDoom shouldn't crash.
Last edited by phantombeta on Wed Jul 26, 2017 3:11 am, edited 2 times in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48375
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: SetStateLabel crashes when called from a static function

Post by Graf Zahl »

What error do you get?
_mental_
 
 
Posts: 3787
Joined: Sun Aug 07, 2011 4:32 am

Re: SetStateLabel crashes when called from a static function

Post by _mental_ »

I guess the sample is not quite correct, as is GZDoom aborts with the following error:

Code: Select all

Script error, ":zscript.txt" line 1:
Unexpected identifier
Expecting 'native' or 'ui' or 'play' or 'version' or '{' or 'clearscope'
Without play it crashes indeed, with additional assertion failure in Debug configuration.
User avatar
phantombeta
Posts: 2011
Joined: Thu May 02, 2013 1:27 am
Graphics Processor: nVidia with Vulkan support

Re: SetStateLabel crashes when called from a static function

Post by phantombeta »

Access violation. It tries to read address 00000050.
Here's a crash report for it.

EDIT:
@_mental_
Apparently that happens if you don't add a "version <x>" to the top of the ZScript file.
I updated the sample to fix that.

EDIT 2:
Actually, from that error, that actually sounds like *another* bug. Either a wrong error message or some bug in the parser or something...
You do not have the required permissions to view the files attached to this post.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48375
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: SetStateLabel crashes when called from a static function

Post by Graf Zahl »

Fixed the crash, but there's a deeper problem lurking here that is not trivial to solve: Resolving a scoped state name will happen in the calling function's context, not the one of the invoking object pointer.

Putting that part on hold because right now I have no good idea how to handle it. It will probably have to defer the check to run time instead of compile time

Return to “On Hold Bugs”