SetStateLabel crashes when called from a static function

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: SetStateLabel crashes when called from a static function

Re: SetStateLabel crashes when called from a static function

by Graf Zahl » Sat Aug 12, 2017 2:08 am

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

Re: SetStateLabel crashes when called from a static function

by phantombeta » Wed Jul 26, 2017 3:08 am

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...
Attachments
SetStateLabelCrashReport.zip
(17.13 KiB) Downloaded 265 times

Re: SetStateLabel crashes when called from a static function

by _mental_ » Wed Jul 26, 2017 3:06 am

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.

Re: SetStateLabel crashes when called from a static function

by Graf Zahl » Wed Jul 26, 2017 2:47 am

What error do you get?

SetStateLabel crashes when called from a static function

by phantombeta » Wed Jul 26, 2017 2:33 am

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.

Top