[ACS+DECO]Game crash when unmorphing (now with a sample)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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.

[ACS+DECO]Game crash when unmorphing (now with a sample)

Postby TDRR » Fri Jan 04, 2019 2:01 pm

Scroll down to the last post to get the runnable sample
Now, like some of you know, in later GZDoom versions DUBG crashes when leaving a vehicle. This also happens with Death Foretold but it uses a different way of unmorphing IIRC.
I'm using a Unmorpher item inheriting from the tome of power:
Code: Select allExpand view
ACTOR Unmorpher : ArtiTomeOfPower
{
Game Doom
+INVENTORY.AUTOACTIVATE
+INVENTORY.QUIET
-INVENTORY.INVBAR
-INVENTORY.PICKUPFLASH
-COUNTITEM
-FLOATBOB
Inventory.PickupMessage ""
Powerup.Duration 1
}

While this works fine in GZDoom 1.8.6 and Zandronum, it doesn't work at all in ZScript-powered versions, instead giving me this VM abort:
Code: Select allExpand view
VM Execution aborted: tried to read from address zero
Called from PlayerPawn.CheckWeaponChange at gzdoom.pk3: zscript/shared/player.txt, line 374
Called from PlayerPawn.TickPSprites at gzdoom.pk3: zscript/shared/player.txt, line 428
Called from PlayerPawn.PlayerThink at gzdoom.pk3: zscript/shared/player.txt, line 1248

For an example use DUBG, it's only 5MB so the download is fast and doesn't take up much space. Choose the Dguy's unknown battlegrounds episode and go into any vehicle you find by pressing the +use key, press it again to get out of the car and trigger the VM abort. All DECORATE code related to these vehicles is found in the VEHICLES lump in the root of the PK3, and in the scripts folder there's ACS code relating to it, but i doubt it has anything to do with the crash.

How can i fix it? Also yes the game crashes when unmorphing anything with this item.
Last edited by TDRR on Tue Sep 17, 2019 5:31 pm, edited 2 times in total.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby Graf Zahl » Fri Jan 04, 2019 4:04 pm

What version did you test with? The stack trace doesn't match 3.7.1.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: [ACS+DECO]Game crash when unmorphing

Postby TDRR » Fri Jan 04, 2019 4:15 pm

Graf Zahl wrote:What version did you test with? The stack trace doesn't match 3.7.1.

I haven't tested it with 3.7.1 because i thought it would be the same as with 3.6.0, but i'm going to try again and put the results here.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby TDRR » Fri Jan 04, 2019 4:30 pm

Eh Performance is even worse than before: 50fps at 640x480 compared to GZDoom 1.8.6 where i get 160fps with max resolution

That aside, here's the current trace:
Code: Select allExpand view
VM Execution aborted: tried to read from address zero
Called from PlayerPawn.CheckWeaponChange at gzdoom.pk3: zscript/shared/player.txt, line 390
Called from PlayerPawn.TickPSprites at gzdoom.pk3: zscript/shared/player.txt, line 444
Called from PlayerPawn.PlayerThink at gzdoom.pk3: zscript/shared/player.txt, line 1449
Last edited by TDRR on Fri Jan 04, 2019 4:42 pm, edited 1 time in total.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby Graf Zahl » Fri Jan 04, 2019 4:41 pm

I was asking because the line number did not match.
If it aborts with a null pointer access there is a bug in the code that needs addressing.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: [ACS+DECO]Game crash when unmorphing

Postby TDRR » Fri Jan 04, 2019 4:43 pm

Graf Zahl wrote:I was asking because the line number did not match.
If it aborts with a null pointer access there is a bug in the code that needs addressing.


I suppose that's in your end? Or do i need to fix something in DUBG?
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby Wivicer » Fri Jan 04, 2019 6:04 pm

No, that's your code. Basically, at some point your code attempts to read a value from something that doesn't have one.
User avatar
Wivicer
 
Joined: 27 Jul 2013
Location: Slowly degrading into a modern-art piece
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby TDRR » Fri Jan 04, 2019 10:48 pm

Wivicer wrote:No, that's your code. Basically, at some point your code attempts to read a value from something that doesn't have one.


Which doesn't make much sense, i'm doing the exact same thing Heretic does except i force it. There isn't anything really wrong with the code as it is.

I think i can't do anything to fix this, short of doing something that just breaks compatibility with older GZDoom versions/Zandronum, which would be even worse. Using that unmorphing ACS special doesn't do anything at all either.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Postby TDRR » Tue Sep 17, 2019 5:30 pm

Here's a runnable sample since Graf once asked me about it:
MorphCrashSample.pk3

Just go to Doom 2 MAP01, grab the chainsaw and press altfire. And BAM! It crashes.
You do not have the required permissions to view the files attached to this post.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby Void Weaver » Tue Sep 17, 2019 8:50 pm

I absolutely have no idea which logic causes game crash (but can assume that game consider initiator of A_GiveInventory as Null, since giver will instntly removes by "Unmorpher" itself), but it can be fixed by calling your "Unmorpher" from external source, smth. like as:

Code: Select allExpand view
ACTOR DoomPlayerExceptItIsAMorph : DoomPlayer
{
   Player.DisplayName "Doom Player except it's a morph"
   Player.MorphWeapon "ChainsawForTesting"
   Translation Ice
   States
   {
   Spawn:
   TNT1 A 0 NoDelay A_SpawnItemEx("UnmorpherOperator",0,0,0,0,0,0,0,SXF_SETMASTER) //Call external actor which will monitoring for unmorphing condition
   Idle:
   PLAY A 1
   Loop
   }
}

ACTOR UnmorpherOperator
{
+NOINTERACTION
States
{
Spawn:
POSS A 1 NoDelay
{
A_Warp(AAPTR_MASTER,0,0,0,0,0,"",0.5); //Just for visualization
If(GetPlayerInput(MODINPUT_BUTTONS,AAPTR_MASTER)&BT_ALTATTACK){A_GiveInventory("Unmorpher",1,AAPTR_MASTER);Return state("Null");} //Any condition; current one: "If my MASTER did press Alt-fire, then give to him "Unmorpher" and self-remove, otherwise return to cycle"
Else{Return state("");}
}
Loop
}
}
Also unmorphing will work correct if the item will be picked up from ground.
User avatar
Void Weaver
Keeper of the Diablo bestiary storage Also amateur DECORATE-spaghetti weaver ಠ_ಠ
 
Joined: 18 Dec 2014

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby TDRR » Tue Sep 17, 2019 9:09 pm

Void Weaver wrote:I absolutely have no idea which logic causes game crash (but can assume that game consider initiator of A_GiveInventory as Null, since giver will instntly removes by "Unmorpher" itself), but it can be fixed by calling your "Unmorpher" from external source, smth. like as:

Code: Select allExpand view
ACTOR DoomPlayerExceptItIsAMorph : DoomPlayer
{
   Player.DisplayName "Doom Player except it's a morph"
   Player.MorphWeapon "ChainsawForTesting"
   Translation Ice
   States
   {
   Spawn:
   TNT1 A 0 NoDelay A_SpawnItemEx("UnmorpherOperator",0,0,0,0,0,0,0,SXF_SETMASTER) //Call external actor which will monitoring for unmorphing condition
   Idle:
   PLAY A 1
   Loop
   }
}

ACTOR UnmorpherOperator
{
+NOINTERACTION
States
{
Spawn:
POSS A 1 NoDelay
{
A_Warp(AAPTR_MASTER,0,0,0,0,0,"",0.5); //Just for visualization
If(GetPlayerInput(MODINPUT_BUTTONS,AAPTR_MASTER)&BT_ALTATTACK){A_GiveInventory("Unmorpher",1,AAPTR_MASTER);Return state("Null");} //Any condition; current one: "If my MASTER did press Alt-fire, then give to him "Unmorpher" and self-remove, otherwise return to cycle"
Else{Return state("");}
}
Loop
}
}


I can't use that, because GetPlayerInput can't be used in Zandronum, not from DECORATE. Also adding an external actor to the mix is probably going to stir up the clientside predictor.

So i'm thinking maybe an ACS script could be done instead and that gives the player the unmorpher item.
Tested it and... YES IT WORKED! Awesome! Thanks for the help Weaver.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby Void Weaver » Tue Sep 17, 2019 9:24 pm

Glad to help you, bro. But the reason of crash is still unclear, hope that a somebody ZScript-pro give a some explanations.

And a some hint: GetPlayerInput work for deco too - GetPlayerInput_(DECORATE). ;)
User avatar
Void Weaver
Keeper of the Diablo bestiary storage Also amateur DECORATE-spaghetti weaver ಠ_ಠ
 
Joined: 18 Dec 2014

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby TDRR » Tue Sep 17, 2019 9:51 pm

Void Weaver wrote:Glad to help you, bro. But the reason of crash is still unclear, hope that a somebody ZScript-pro give a some explanations.

And a some hint: GetPlayerInput work for deco too - GetPlayerInput_(DECORATE). ;)


Yes it indeed seems to be that the caller of the action (The weapon) is taken away by the Unmorph item, and then ZDoom gets confused and dies.

It works for DECORATE, but that's not the case in Zandronum. Remember Zandronum is based on GZD 1.8.6, a version from 2014.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby Boondorl » Wed Sep 18, 2019 6:54 am

I found the culprit. It's this line right here in the UndoPlayerMorph function in player_morph.zs (around line 257):
Code: Select allExpand view
self.player = null;

which causes the game to crash. I'm not sure why this is being done, but moving the line around doesn't help, and given the stack trace above which mentions CheckWeaponSwitch, I'm guessing at some point a safety check isn't being done properly and it's trying to read from the now null self.player.
User avatar
Boondorl
 
Joined: 12 Jul 2018

Re: [ACS+DECO]Game crash when unmorphing (now with a sample)

Postby TDRR » Wed Sep 18, 2019 8:11 am

Boondorl wrote:I found the culprit. It's this line right here in the UndoPlayerMorph function in player_morph.zs (around line 257):
Code: Select allExpand view
self.player = null;

which causes the game to crash. I'm not sure why this is being done, but moving the line around doesn't help, and given the stack trace above which mentions CheckWeaponSwitch, I'm guessing at some point a safety check isn't being done properly and it's trying to read from the now null self.player.

That line doesn't make sense IMO. Maybe that's an oversight or something? Still stupid i have been chasing nothing but a smoke trail and i had to fix it with a crappy workaround, shame having compatibility with Zandro and modern GZDoom is quite hard.
User avatar
TDRR
A living work in progress
 
Joined: 11 Mar 2018
Location: Venezuela
Discord: TDRR#5820
Operating System: Windows Vista/7/2008 64-bit
Graphics Processor: Intel (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: Gifty and 0 guests