[Fixed] Arrays of dynarrays can't be indexed correctly

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Arrays of dynarrays can't be indexed correctly

Postby phantombeta » Tue Jan 08, 2019 11:18 am

When you try to index a dynarray contained inside an array with a non-constant index, it'll error out with "Invalid resizable array".
Code: Select allExpand view
    void foo () {
        Array<int> a [5];
        a.Push (555);

        a [3] [0] = 666; // This works fine
        int b = random (0, 255);
        a [b] [0] = 666; // This errors out
    }


Steps to reproduce:
  • Try to load the example PK3

I'd really like to see this bug fixed. Right now, the only way to get the array's contents is to copy it to a local variable.
I actually tried to see if I could fix it myself, but couldn't figure anything out. :\
Attachments
NestedDynArrayIndexBug.PK3
(371 Bytes) Downloaded 12 times
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Arrays of dynarrays can't be indexed correctly

Postby Graf Zahl » Tue Jan 08, 2019 11:25 am

phantombeta wrote:I actually tried to see if I could fix it myself, but couldn't figure anything out. :\


Welcome to the club. :( This one got me, too.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Arrays of dynarrays can't be indexed correctly

Postby phantombeta » Tue Jan 08, 2019 11:49 am

One thing I did figure out is that the constant case works because it pretty much turns constant index array accesses into temporary fields, if that helps at all.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Arrays of dynarrays can't be indexed correctly

Postby Graf Zahl » Tue Jan 08, 2019 1:16 pm

I ran into this myself when scriptifying the AutouseHealth function, but I didn't manage to fix it.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Yet Another Array Fix By phantombeta

Postby phantombeta » Wed Mar 13, 2019 5:28 am

Fuckssake, the solution was sitting right there in front me the whole time.
Arrays of dynarrays simply needed to be special-cased so that the address of their size value is calculated at runtime instead of compile-time.
PR link.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Arrays of dynarrays can't be indexed correctly

Postby Graf Zahl » Wed Mar 13, 2019 6:43 am

That's very much appreciated.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Closed Bugs

Who is online

Users browsing this forum: m8f and 0 guests