SetStateLabel crashes when called from a static function

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

Moderator: GZDoom Developers

SetStateLabel crashes when called from a static function

Postby 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 allExpand view
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 allExpand view
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
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: Brazil, South America, Earth, Orion-Cygnus Arm, Milky Way
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: SetStateLabel crashes when called from a static function

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

What error do you get?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: SetStateLabel crashes when called from a static function

Postby _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 allExpand view
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.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: SetStateLabel crashes when called from a static function

Postby 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 73 times
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: Brazil, South America, Earth, Orion-Cygnus Arm, Milky Way
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: SetStateLabel crashes when called from a static function

Postby 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
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to On Hold Bugs

Who is online

Users browsing this forum: No registered users and 2 guests