Script errors with 4.14.0

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
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Script errors with 4.14.0

Post by Enjay »

[Edit: With help from the community, the reason for the changes have been explained and the fixes that I needed to get my projects working again were provided.

Reason for the changes: viewtopic.php?t=79997 further exemplified by Player701 below
m8f's fixed Gearbox mod: Release page on GitHub forum thread: viewtopic.php?t=71086
Player 701's fix for the PDA code: viewtopic.php?p=1257238#p1257238 forum thread for the original PDA kit viewtopic.php?t=65849

Thank you to those who provided insight and explanations, and for providing what I needed (and what others will need) to get things working again. ]


Original Post...
Spoiler:
User avatar
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Script errors with 4.14.0

Post by Enjay »

For what it's worth, I just tried a few git builds.

gzdoom-x64-g4.14pre-120-gfb660fa3c.7z
from December 05 does not throw up the errors and appears to work.

gzdoom-x64-g4.14pre-121-g325817afd.7z
from December 13 does throw up the errors and the game cannot start.
User avatar
inkoalawetrust
Posts: 86
Joined: Mon Aug 26, 2019 9:18 pm
Graphics Processor: nVidia with Vulkan support

Re: Script errors with 4.14.0

Post by inkoalawetrust »

This is because Jay pushed a fix for ZScript that makes arrays more strictly obey what type they're supposed to be. For Gearbox at least, there was a discussion on the ZDoom Discord where the cause of the error seemed to be that m8f was using a TextureID array by passing actual plain integer values into it, hence the "Cannot convert SInt4 to TextureID" errors.

I don't think much can be done about it besides updating the mods to be coded better. Since AFAIK Jay did try to make the array fix only apply to 4.14.0+, but that'd just break more things.
User avatar
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Script errors with 4.14.0

Post by Enjay »

Thanks for the context and explanation. I guess I was right to think along the lines of "it's a problem that needs to be addressed in the scripts rather than a bug."

The downside is that the fixes are beyond me. So I'm trapped in older versions of GZDoom for what I was working on until I can get it resolved somehow. Tying a mod to a specific old version is never a good policy IMO. So, I hope I can get something worked out somehow.

Shame it's not something that could be versioned to pre 4.14.0 I know a handful of mods used the PDA kit, and quite a few more used the Gearbox. So, I guess they will be broken on new GZDoom. However, it does sound like it was a considered decision.
User avatar
Player701
 
 
Posts: 1706
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Script errors with 4.14.0

Post by Player701 »

IMO, with a breaking change like this one, the devs should've made an announcement before the 4.14 release, providing at least a couple relatively simple ZScript examples that worked in older versions but would break in the next release. It would've been much easier to understand what is going on here, as I still don't quite grasp it entirely except for the fact that it has something to do with more strict type checking. Fortunately, at least my own project does not seem to be affected.
User avatar
Nash
 
 
Posts: 17481
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Script errors with 4.14.0

Post by Nash »

I'll get around to updating my PDA mod eventually. No time frame, except "as soon as possible". Sorry for the inconvenience.

That said, the engine fixes are absolutely needed and is non-negotiable, so I'm on board with the rest of the team. Leaving code exploits open is never a good thing.
User avatar
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Script errors with 4.14.0

Post by Enjay »

I really appreciate that Nash. I look forward to the fix as and when you have time for it.

I've been around long enough to know that a mod-breaking change in code would not have been a decision taken lightly. Usually even quite extreme steps are taken to ensure compatibility. So, I'm quite content that the decision was made for very good reasons.
User avatar
Player701
 
 
Posts: 1706
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Script errors with 4.14.0

Post by Player701 »

Since no one apparently bothered to provide any example code, I've had to conduct my own investigation. Here's something I've managed to come up with so you can see why the breaking change had to be made:

Code: Select all

version "4.10"

class TestInv : Inventory
{
    Array<class<Actor> > ar;
    
    override bool Use(bool pickup)
    {
        voidptr evil = new('Object'); // Or anything else, really
        ar.Push(evil); // Illegal in ZScript >= 4.11 OR GZDoom >= 4.14
        
        class<Actor> cls = ar[0];
        Spawn(cls, (0, 0, 0)); // This causes GZDoom to crash
        ar.Clear();

        return false;
    }
}
Running this code and typing give testinv and then use testinv will typically cause GZDoom to crash.

What happens here is that we are able to coerce the ZScript engine to treat an Object as if it were a class<Actor> - which obviously causes all sorts of unexpected behavior when we try to peform any kind of operation on it, like attempting to spawn this "actor" in the level. In this particular example, GZDoom will simply crash, but I suspect that instead of new('Object'), it is possible to provide a pointer to some carefully constructed object instance that might result in arbitrary code execution when operated upon in a specific way.

Now I wouldn't imagine an actual gameplay mod to contain any such code, so why did some mods still break when this exploit was fixed, you might ask? In Enjay's case, there are two particular scenarios affected by the fix. The first one:

Code: Select all

version "4.10"

class Base
{
}

class Derived : Base
{
}

class Test
{
    Array<Derived> ar;

    void Demo(Base b)
    {
        ar.Find(b); // Illegal in ZScript >= 4.11 OR GZDoom >= 4.14
    }
}
Do you see the problem here? We have an array of Derived, but we provide a pointer to Base as an argument to Find. This is technically illegal because a pointer to Base is not guaranteed to also point to Derived, although it won't cause any issues at run-time because the contents of the array are not modified - not that the compiler actually cares about this any longer, so the above code is now invalid regardless of the ZScript version being used. Note that replacing Find with Push (or Insert, for that matter) will error out even in older versions - there is special handling for these methods in the compiler in case the array contains object pointers. But what about other types? That's what the second example is about:

Code: Select all

class Test
{
    Array<TextureID> ar;
    
    void Demo()
    {
        ar.Push(12345); // Illegal in ZScript >= 4.11 OR GZDoom >= 4.14
    }
}
From a practical standpoint, there is really nothing wrong here because a TextureID is, in fact, just a number. But from the type system's point of view, a number and a TextureID are quite different things, so this code is not supposed to be valid ZScript - it only used to work due to an oversight. This particular scenario has already been discussed previously in this very thread, so there is not much else here to say.
User avatar
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Script errors with 4.14.0

Post by Enjay »

Presumably, in 4.14.0 your code examples would just cause GZDoom to refuse to run, citing the specific lines of code as problematic, whereas, previously, they would have been allowed through?


In other news, m8f has released a fix for the Weapons/Inventory Gearbox so it now works with 4.14.0. I'm sure that will be much appreciated by many.

So, from my perspective, that only leaves the problem with the PDA code.
It seems only to be in the area that I quoted in my first post that is problematic, but I don't know how significant a re-write would be needed to fix it. From my uninformed position, it could be anything from a simple change of data type to a complete re-write of the entire thing. (And, I guess, perhaps fixing one thing may cascade to other things needing fixed too.)

So, can anyone suggest something that I might be able to do to to correct it in the meantime? It would allow me to get on with working on the latest game version instead of keeping an old exe around for the sake of this one problem. I know that Nash will look at the PDA kit in due course (which is absolutely fine, much appreciated and there is no implied pressure at all), but if I can get things working with a tweak to the old code in the short-term, that would be useful.
User avatar
Player701
 
 
Posts: 1706
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: Script errors with 4.14.0

Post by Player701 »

Enjay wrote: Wed Dec 25, 2024 5:07 am whereas, previously, they would have been allowed through?
Correct, but only with ZScript version 4.10 or below. Previously, the fix was conditionally applied only for ZScript 4.11 and above, but starting with GZDoom 4.14, the fix is applied unconditionally regardless of the ZScript version declared.
Enjay wrote: Wed Dec 25, 2024 5:07 am So, from my perspective, that only leaves the problem with the PDA code.
I found the PDA mod code on Github while examining the issue. The problem is with the type of argument given to Find:

Code: Select all

int index = menu.pdaList.items.Find(PDAColoredButton(caller));
Here, menu.pdaList.items is of type PDAOwnedPDAButton. However, the argument is cast to PDAColoredButton, which is the parent class. Exactly the same as the example scenario with Base and Derived above.

To fix this, try replacing the cast as follows:

Code: Select all

int index = menu.pdaList.items.Find(PDAOwnedPDAButton(caller));
User avatar
Enjay
 
 
Posts: 26872
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Script errors with 4.14.0

Post by Enjay »

Player701 wrote: Wed Dec 25, 2024 5:45 am I found the PDA mod code on Github while examining the issue. The problem is with the type of argument given to Find:

Code: Select all

int index = menu.pdaList.items.Find(PDAColoredButton(caller));
Here, menu.pdaList.items is of type PDAOwnedPDAButton. However, the argument is cast to PDAColoredButton, which is the parent class. Exactly the same as the example scenario with Base and Derived above.

To fix this, try replacing the cast as follows:

Code: Select all

int index = menu.pdaList.items.Find(PDAOwnedPDAButton(caller));
Marvellous! Thank you very much. With that change (and with the fixed Gearbox) I can get GZDoom to start. On a quick check, the PDAs that I have defined seem to be working perfectly. Very much appreciated, thank you again.

Return to “Scripting”