[Fixed] Overridden defaulted arguments don't get set

Bugs that have been investigated and resolved somehow.

Moderator: Developers

Overridden defaulted arguments don't get set

Postby Marrub » Sat Jan 27, 2018 11:50 am

If one creates an override for DamageMobj with the signature:
Code: Select allExpand view
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 allExpand view
override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags = 0, double angle = 0)
User avatar
Marrub
Xevv Va Rkvyr
 
 
 
Joined: 26 Feb 2013
Discord: Marrub#5455
Twitch ID: marrubdaskuleion

Re: Overridden defaulted arguments don't get set

Postby XxMiltenXx » Sat Jan 27, 2018 1:31 pm

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.
XxMiltenXx
 
Joined: 08 Jan 2014

Re: Overridden defaulted arguments don't get set

Postby Marrub » Sat Jan 27, 2018 2:05 pm

The issue is that if you don't have them in the override signature it will crash, not that there are defaultable arguments.
User avatar
Marrub
Xevv Va Rkvyr
 
 
 
Joined: 26 Feb 2013
Discord: Marrub#5455
Twitch ID: marrubdaskuleion

Re: Overridden defaulted arguments don't get set

Postby _mental_ » Sat Jan 27, 2018 3:46 pm

I added the following code to ZombieMan class and it works fine
Code: Select allExpand view
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.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Overridden defaulted arguments don't get set

Postby Marrub » Sat Jan 27, 2018 4:22 pm

_mental_ wrote:I added the following code to ZombieMan class and it works fine
Code: Select allExpand view
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 allExpand view
override bool TryPickup(Actor mo)

will cause crashing if, for instance, this is done:
Code: Select allExpand view
if(mo is "PlayerPawn") return true;


However, of course, the correct function signature works fine:
Code: Select allExpand view
override bool TryPickup(in out Actor mo)
User avatar
Marrub
Xevv Va Rkvyr
 
 
 
Joined: 26 Feb 2013
Discord: Marrub#5455
Twitch ID: marrubdaskuleion

Re: Overridden defaulted arguments don't get set

Postby Graf Zahl » Sat Jan 27, 2018 4:35 pm

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 Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Overridden defaulted arguments don't get set

Postby Graf Zahl » Thu Mar 01, 2018 9:03 am

Quick note: This is the last one that needs fixing before preparing a new release.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Overridden defaulted arguments don't get set

Postby drfrag » Thu Mar 01, 2018 10:04 am

And checking the solution to the cvar protection compatibility issues by _mental_ (cvar_safe_value branch).
User avatar
drfrag
I.R developer, I.R smart
Vintage GZDoom Developer
 
Joined: 23 Apr 2004
Location: Spain

Re: Overridden defaulted arguments don't get set

Postby Graf Zahl » Thu Mar 01, 2018 10:07 am

Is that branch complete?
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Overridden defaulted arguments don't get set

Postby _mental_ » Thu Mar 01, 2018 10:28 am

Yes, it's just one relatively small change.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Overridden defaulted arguments don't get set

Postby ZippeyKeys12 » Tue Mar 13, 2018 7:18 pm

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 allExpand view
Script error, "aaa.zip:zscript.zsc" line 11:
Insufficient arguments in call to DamageMobj
ZippeyKeys12
 
Joined: 15 Jun 2016

Re: Overridden defaulted arguments don't get set

Postby Graf Zahl » Wed Mar 14, 2018 2:56 am

Can you retest this with the latest devbuild?
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Overridden defaulted arguments don't get set

Postby _mental_ » Wed Mar 14, 2018 8:11 am

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 allExpand view
:zscript.txt, line 5: Default values for parameter of virtual override will be ignored!
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Overridden defaulted arguments don't get set

Postby Graf Zahl » Wed Mar 14, 2018 8:46 am

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

Re: Overridden defaulted arguments don't get set

Postby ZippeyKeys12 » Wed Mar 14, 2018 10:45 am

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.
ZippeyKeys12
 
Joined: 15 Jun 2016

Next

Return to Closed Bugs

Who is online

Users browsing this forum: No registered users and 1 guest