ReadLump data is read twice when lumps accumulate

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!

ReadLump data is read twice when lumps accumulate

Postby Nash » Sat Dec 01, 2018 8:47 am

Code: Select allExpand view

    void ReadTestLump
(void)
    {
        
testData.Clear();

        
int lump = -1;
        while (-
!= (lump Wads.FindLump('TESTLUMP'lump 1)))
        {
            
String data Wads.ReadLump(lump);

            
// split lines
            
Array<Stringlines;
            
data.Split(lines"\n"TOK_KEEPEMPTY);

            
// strip comments
            
for (int i 0lines.Size(); i++)
            {
                if (
lines[i].IndexOf("//") == 0)
                {
                    continue;
                }
                else
                {
                    
testData.Push(lines[i]);
                }
            }
        }

        
//Console.Printf("size: %d", testData.Size());
        
for (int i 0testData.Size(); i++)
        {
            
// delete that weird character that gets added at the end
            
testData[i].Truncate(testData[i].Length() - 1);

            if (
testData[i])
            {
                
Console.Printf("%s\n"testData[i]);
            }
        }
    }
 


Load ReadLump.pk3 and ReadLump Mod.pk3, in that order. If a second TestLump.txt is added into your load order, the data contents from the first lump be listed twice. Why does this happen?
Attachments
ReadLump Mod.pk3
(221 Bytes) Downloaded 14 times
ReadLump.pk3
(1.13 KiB) Downloaded 13 times
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: ReadLump data is read twice when lumps accumulate

Postby phantombeta » Sat Dec 01, 2018 10:40 am

Somewhat user error, actually. Caused by an insane, non-sensical, ill-advised, terrible decision in the ZScript compiler.
Function-local variables are never initialized at all. The VM's registers are, but that only happens once, so any variables defined after anything that isn't a variable definition will contain garbage data. And this extends to dynamic arrays.

TL;DR User error caused by a terrible design decision in the ZScript compiler. Always clear your dynamic arrays.
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: ReadLump data is read twice when lumps accumulate

Postby Graf Zahl » Sat Dec 01, 2018 1:48 pm

This here is actually a real bug. Arrays get initialized at function init, but obviously require a Clear when being declared within a loop.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ReadLump data is read twice when lumps accumulate

Postby Nash » Sat Dec 01, 2018 3:35 pm

Should this thread be moved to Bugs, then?
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: ReadLump data is read twice when lumps accumulate

Postby Graf Zahl » Sat Dec 01, 2018 4:23 pm

Sure. But you can also fix it on your side by clearing the array right after the declaration.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ReadLump data is read twice when lumps accumulate

Postby Ozymandias81 » Mon Dec 03, 2018 1:30 pm

Could be this issue related to this one? Since I load BoA as resource folder from GZDBuilder under GZDoom, there are gzdoom related pk3s loading before BoA...
User avatar
Ozymandias81
Doom is a State of Mind... Out of Control.
 
Joined: 04 Jul 2013
Location: Mount Olympus, Mars
Github ID: Ozymandias81
Operating System: Windows Vista/7 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: ReadLump data is read twice when lumps accumulate

Postby Graf Zahl » Mon Dec 03, 2018 1:38 pm

Are you using ZScript arrays?
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: ReadLump data is read twice when lumps accumulate

Postby Ozymandias81 » Mon Dec 03, 2018 1:42 pm

I am not the one who is coding with zscript since I am not familiar with it, but yes we are using it
User avatar
Ozymandias81
Doom is a State of Mind... Out of Control.
 
Joined: 04 Jul 2013
Location: Mount Olympus, Mars
Github ID: Ozymandias81
Operating System: Windows Vista/7 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: ReadLump data is read twice when lumps accumulate

Postby Graf Zahl » Mon Dec 03, 2018 1:49 pm

Then check if you define an array inside a for or while loop. That is the only condition which can trigger this.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Bugs

Who is online

Users browsing this forum: No registered users and 2 guests