Overridden defaulted arguments don't get set

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
Marrub
 
 
Posts: 1192
Joined: Tue Feb 26, 2013 2:48 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Arch Linux
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Contact:

Overridden defaulted arguments don't get set

Post by Marrub »

If one creates an override for DamageMobj with the signature:

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags, double angle)
The VM will fail to fill the flags and angle arguments and crash.
This works fine, however, if you make the signature this:

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags = 0, double angle = 0)
XxMiltenXx
Posts: 219
Joined: Wed Jan 08, 2014 8:40 am
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by XxMiltenXx »

I think this is intentional, as these are the default values that get used if those variables aren't passed when the function is called and you have to override the function first as it was originally written.

I think to have those filled automatically is rather a "feature" then, rather than a bug.
User avatar
Marrub
 
 
Posts: 1192
Joined: Tue Feb 26, 2013 2:48 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Arch Linux
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Contact:

Re: Overridden defaulted arguments don't get set

Post by Marrub »

The issue is that if you don't have them in the override signature it will crash, not that there are defaultable arguments.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Overridden defaulted arguments don't get set

Post by _mental_ »

I added the following code to ZombieMan class and it works fine

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags, double angle)
{
	return super.DamageMobj(inflictor, source, damage, mod, flags, angle);
}
Please post a complete runnable sample.
User avatar
Marrub
 
 
Posts: 1192
Joined: Tue Feb 26, 2013 2:48 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Arch Linux
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Contact:

Re: Overridden defaulted arguments don't get set

Post by Marrub »

_mental_ wrote:I added the following code to ZombieMan class and it works fine

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags, double angle)
{
	return super.DamageMobj(inflictor, source, damage, mod, flags, angle);
}
Please post a complete runnable sample.
Sorry, I should have been more specific, it crashes when you call DamageMobj with omitted parameters. The only place in the source that I know of that does this is A_VileAttack, which if you get hit by it as a player, will crash.

Also a related issue, not sure if it needs its own thread: Omitting parameter attributes will cause other weird buginess, including crashing, but not emit a warning or error.
For instance, the override signature in an Inventory-derived class:

Code: Select all

override bool TryPickup(Actor mo)
will cause crashing if, for instance, this is done:

Code: Select all

if(mo is "PlayerPawn") return true;
However, of course, the correct function signature works fine:

Code: Select all

override bool TryPickup(in out Actor mo)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by Graf Zahl »

The latter one is a completely unrelated issue. Apparently the modifier flags are not checked properly when comparing signatures.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by Graf Zahl »

Quick note: This is the last one that needs fixing before preparing a new release.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3141
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: Overridden defaulted arguments don't get set

Post by drfrag »

And checking the solution to the cvar protection compatibility issues by _mental_ (cvar_safe_value branch).
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by Graf Zahl »

Is that branch complete?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Overridden defaulted arguments don't get set

Post by _mental_ »

Yes, it's just one relatively small change.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: Overridden defaulted arguments don't get set

Post by ZippeyKeys12 »

This might be the same error, marrub's appears to occur in game while mine occurs during loading.
Spoiler: Working Code
Spoiler: Error
And the error code gives me:

Code: Select all

Script error, "aaa.zip:zscript.zsc" line 11:
Insufficient arguments in call to DamageMobj
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by Graf Zahl »

Can you retest this with the latest devbuild?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Overridden defaulted arguments don't get set

Post by _mental_ »

Unfortunately it doesn't work with the latest code at the moment.
It's a bit different issue though: default values are ignored when virtual function is overridden.

The working sample gives the following warning

Code: Select all

:zscript.txt, line 5: Default values for parameter of virtual override will be ignored!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Overridden defaulted arguments don't get set

Post by Graf Zahl »

That warning is fully intentional. Specifying defaults for an override should not be possible and in ZScript 3.3 will error out.
The main problem here is that the missing parameters get filled in by the called function so leaving out some arguments where the defaults differ would create unpredictable behavior because the default arguments that get set depend on the actual class type and not the calling pointer type. As a consequence these defaults will get ignored now and a warning emitted in older ZScript versions, and an error in the new one.
If that is all you get for the two different scripts, all works as intended.
ZippeyKeys12
Posts: 111
Joined: Wed Jun 15, 2016 2:49 pm

Re: Overridden defaulted arguments don't get set

Post by ZippeyKeys12 »

The warning is obviously intentional, the problem is that it gives an insufficient arguments error when a function call omits arguments that have defaults in gzdoom.pk3.
Also, I'm using whatever was the latest devbuild yesterday.
Post Reply

Return to “Closed Bugs [GZDoom]”