[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.

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!)
User avatar
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

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

Post by TDRR »

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 all

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 all

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ACS+DECO]Game crash when unmorphing

Post by Graf Zahl »

What version did you test with? The stack trace doesn't match 3.7.1.
User avatar
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: [ACS+DECO]Game crash when unmorphing

Post by TDRR »

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
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: [ACS+DECO]Game crash when unmorphing

Post by TDRR »

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 all

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ACS+DECO]Game crash when unmorphing

Post by Graf Zahl »

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
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: [ACS+DECO]Game crash when unmorphing

Post by TDRR »

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
Wivicer
Posts: 367
Joined: Sat Jul 27, 2013 4:39 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: [ACS+DECO]Game crash when unmorphing

Post by Wivicer »

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
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: [ACS+DECO]Game crash when unmorphing

Post by TDRR »

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
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: [ACS+DECO]Game crash when unmorphing

Post by TDRR »

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
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am

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

Post by Void Weaver »

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 all

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
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

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

Post by TDRR »

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 all

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
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am

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

Post by Void Weaver »

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
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

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

Post by TDRR »

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
Boondorl
Posts: 145
Joined: Wed Jul 11, 2018 10:57 pm

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

Post by Boondorl »

I found the culprit. It's this line right here in the UndoPlayerMorph function in player_morph.zs (around line 257):

Code: Select all

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
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

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

Post by TDRR »

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 all

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.

Return to “Scripting”