Page 1 of 1

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

Posted: Fri Jan 04, 2019 2:01 pm
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.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 4:04 pm
by Graf Zahl
What version did you test with? The stack trace doesn't match 3.7.1.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 4:15 pm
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.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 4:30 pm
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

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 4:41 pm
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.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 4:43 pm
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?

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 6:04 pm
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.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Fri Jan 04, 2019 10:48 pm
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.

Re: [ACS+DECO]Game crash when unmorphing

Posted: Tue Sep 17, 2019 5:30 pm
by TDRR
Here's a runnable sample since Graf once asked me about it:
MorphCrashSample.pk3
(718 Bytes) Downloaded 87 times
Just go to Doom 2 MAP01, grab the chainsaw and press altfire. And BAM! It crashes.

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

Posted: Tue Sep 17, 2019 8:50 pm
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.

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

Posted: Tue Sep 17, 2019 9:09 pm
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.

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

Posted: Tue Sep 17, 2019 9:24 pm
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). ;)

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

Posted: Tue Sep 17, 2019 9:51 pm
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.

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

Posted: Wed Sep 18, 2019 6:54 am
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.

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

Posted: Wed Sep 18, 2019 8:11 am
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.