Zforms example gzdoom crash

Sun Sep 05, 2021 1:39 am

Hi, I wanted to learn how to make menus using the Zforms, but I have necountered serious problem.

I downloaded the github example from (https://github.com/Doom2fan/ZFormsExamples) and tried running it to see how it looks.
Console command "openmenu Samples_ZF_DynamicElementCreation" works and brings the sample dyamic element showing owned weapons.
Console command "openmenu Samples_ZF_SimpleMenu" brings gzdoom to desktop crash with the only error saying "Access violation - trying to read from adress zero". Nothing else, so I cannot provide more info, neither I can debug anything. It certainly cannot access something, but I don't know what, because it shows no other error.
I'm using gzdoom 4.6.0.

What is going on? I mean, how an I supposed to run this example? It certainly is bugged, but my skill is too low to debug this. Would anyone help me?

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 2:54 am

I have encountered the same issue and the reason to it is that the version 1.0 of ZForms is broken with the current GZDoom.
If you want to use ZForms, you have to download the newest master here.

However all the code provided in the ZFormsExamples is valid and works with the newest master of ZForms, so it's still a good source of learning how to use it.
Another source of information that helped me a ton is the documentation.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 3:05 am

I can't check things right now, but any idea if this bug in zforms will affect Nash's PDA starter kit? I have used the PDA kit quite recently and did not experience a crash but perhaps I simply didn't do something that would trigger it?

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 3:10 am

The crash happens when you define a button in the 1.0 release of ZForms.
Nash's PDA however works fine while having a lot of buttons, so I assume Nash either fixed it or used a newer version of ZForms.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 3:25 am

Thanks for the info. Looking at the relevant forum, it looks like Nash released the most recent version of the PDA kit in November 2020 which, presumably, is before the bug with 4.6.1 raised its head and prompted a fix in ZForms? If so, I guess Nash must have fixed it in the PDA starter kit code. Thanks again.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 4:21 am

Jarewill wrote:I have encountered the same issue and the reason to it is that the version 1.0 of ZForms is broken with the current GZDoom.
If you want to use ZForms, you have to download the newest master here.

However all the code provided in the ZFormsExamples is valid and works with the newest master of ZForms, so it's still a good source of learning how to use it.
Another source of information that helped me a ton is the documentation.


Oh, great. I actually already downloaded the zforms master and personalized it for my use with the python script.
So, all I have to do now is actually make the menu and try it. Great, just great.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 4:26 am

If you copy the menus from the Examples file and change a few class names, it should still work.
The issue was with the ZForms files and not with the menus provided in Examples.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 6:16 am

Umm, not actucally completely true. I tried following the example, making new menu...and some methods used in the example looks like being changed.

Code:
class soaMenuHandler : soa_ZF_Handler {
    soaMenu link;
    override void buttonClickCommand(soa_ZF_Button caller, string command) {
        if ( command == "soaButton01" ) {
            //button action here
            link.soaLabel.setTextColor = random [textColor] (Font.CR_BRICK, Font.CR_TEAL);
        }
    }
}
class soaMenu : soa_ZF_GenericMenu {
    soaMenuHandler handler;
    Font smallfont;
    soa_ZF_Image background;
    soa_ZF_Button soaButton01;
    soa_ZF_Label soaLabel;

    override void Init (Menu parent) {
        Vector2 baseRes = (320, 200);

        Super.Init(parent);

        SetBaseResolution(baseRes);

        smallfont = OptionFont();

        handler = new("soaMenuHandler");
        handler.link = self;

        background = soa_ZF_Image.Create (
            (0, 0),//position
            (320, 200), //size
            "graphics/soaMenu/Panel.png",//image path/name
            soa_ZF_Image.AlignType_TopLeft
        );
        background.Pack(mainFrame);

        // Create the box image's textures.
        let boxTexture = soa_ZF_BoxTextures.CreateTexturePixels (
            "graphics/soaMenu/BoxTexture.png",//the texture itself
            (32, 32), //top-left corner of the middle of the box
            (64, 64), //bottom-right corner of the middle of the box
            false, //scale-true, tile-false the sides
            false //scale-true, tile-false the middle
        );
        //add a box image
        let boxSize = (128, 128);
        let aBoxImage = soa_ZF_BoxImage.Create (
            ((baseRes.X - boxSize.X) / 2.0, (baseRes.Y - boxSize.Y) / 2.0), //position
            boxSize, //size
            boxTexture, //texture
            (0.25, 0.25) //scale
        );
        aBoxImage.Pack(mainFrame);

        //create the button's textures
        let buttonIdle = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/SmallButtonIdle.png", true);
        let buttonHover = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/SmallButtonHovered.png", false);
        let buttonClick = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/SmallButtonClicked.png", false);

        //add a button
        soaButton01 = soa_ZF_Button.Create (
            ((baseRes.X - 18.0) / 2.0, (baseRes.Y - 18.0) / 2.0),//position
            (18, 18), //size
            cmdHandler : handler, //command handler
            command : "soaButton01", //command string for button
            inactive: buttonIdle,
            hover: buttonHover,
            click: buttonClick
        );
        soaButton01.Pack(mainFrame);

        //add a label
        soaLabel = soa_ZF_Label.Create(
            (0, soaButton01.box.pos.Y + soaButton01.box.size.Y + 4), //position  //<<<Getting error here, saying the protected member 'box' cannot be accessed. I don't know how to change this, since I cant figure out where the box is defined...
            (0, smallFont.GetHeight()),
            text: "Click me!", //label's text
            fnt: smallFont, //font to use
            wrap: false, //auto text wrap
            autoSize: true, //auto resize elements
            textColor: Font.CR_WHITE //text color
        );
        // Calculate the horizontal position for the label so that it's centered on the screen.
        soaLabel.box.pos.X = baseRes.x - smallFont/stringWidth(soaLabel.text) / 2.0; //<<<Also, Getting error here, saying the protected member 'box' cannot be accessed. I don't know how to change this, since I cant figure out where the box is defined...
        //add element ot mainframe
        soaLabel.Pack(mainFrame);
    }
}


(0, soaButton01.box.pos.Y + soaButton01.box.size.Y + 4), //position //<<<Getting error here, saying the protected member 'box' cannot be accessed. I don't know how to change this, since I cant figure out where the box is defined...

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 8:09 am

Ah, yeah, a few things have to be changed it seems.
You cannot access the pos and size variables like this anymore, now you have to use the GetPos and GetSize functions.

Also you can specify a label directly in the button as the third argument (after size, before cmdHandler)

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 9:09 am

No, I actually didn't "fix" anything in the ZForms of my PDA Starter Kit. I was using just whatever stock release that was available at the time. Unfortunately I don't remember if it was a "stable" release or not.

Fair warning, ZForms "latest master" as of today is WIP code, it's ZForms 2.0, which is incompatible with ZForms 1.0 (very big API changes). It's not complete yet and there's no official documentation and even I myself haven't upgraded in my ZForms-based projects... not wise to work with moving targets...

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 9:53 am

jarewill: Many thanks. I've never workd with UI before, so it is pretty new to me.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 9:58 am

Nash wrote:No, I actually didn't "fix" anything in the ZForms of my PDA Starter Kit. I was using just whatever stock release that was available at the time. Unfortunately I don't remember if it was a "stable" release or not.

Well, either by luck or design, the PDA starter kit (and projects based off it) seem to still be working as intended. :thumb:

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 10:26 am

The PDA starter kit is probably not using any tiling textures, nor box/multi-textures. It's also using a version of ZForms from before single-texture button rendering and API was unified with box/multi-textures, so that doesn't use Shape2D either.
Also, this crash has been fixed in GZDoom itself, as far as I know, it's just not in a stable release yet.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 2:28 pm

So, it's not using any of the features that cause the crash and uses a version of ZForms that didn't even have one of the features where the crash could happen. That would certainly explain the lack of crashing with the PDA Starter kit. :yup:

And a GZDoom-side fix is pending an official release. Also good to know.

Thank you kindly.

Re: Zforms example gzdoom crash

Sun Sep 05, 2021 2:43 pm

phantombeta wrote:The PDA starter kit is probably not using any tiling textures, nor box/multi-textures. It's also using a version of ZForms from before single-texture button rendering and API was unified with box/multi-textures, so that doesn't use Shape2D either.
Also, this crash has been fixed in GZDoom itself, as far as I know, it's just not in a stable release yet.

Oh, I see. Thanks for the information!
However I already started using a master of ZForms, (not current one, but a recent one, unsure which) so should I switch back to 1.0 or wait for the 2.0 version that's in the works?