[ZScript] Lost first string function parameter

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

[ZScript] Lost first string function parameter

Post by m8f »

Sorry, I couldn't make a better title.

Here is the minimal working example of the bug:
lost-parameter.pk3
(1.06 KiB) Downloaded 18 times
Just run the mod and examine the console output.

Expected result: console contains 130 rows of numbers that look like this:

Code: Select all

1_000 2_000
1_001 2_001
1_002 2_002
1_003 2_003
...
1_127 2_127
1_128 2_128
1_129 2_129
Note that the first column always contains "1_", and the second column always contains "2_".

Actual result: console contains the following 130 rows:

Code: Select all

1_000 2_000
1_001 2_001
1_002 2_002
1_003 2_003
...
1_124 2_124
1_125 2_125
1_126 2_126
1_127 2_127
2_128 2_128
2_129 2_129
Note that last rows contain "2_" instead of "1_" in the first row.
Strings "1_128" and "1_129" are never printed, and strings "2_128" and "2_129" are printed twice.

What does the example contain?
1. A function with two string parameters.
2. This function is called 130 times with different strings. The first parameter is always in format "1_N", where N is the function call number, counting from 0. The second parameter is in format "2_N". Therefore, there are 130 unique first parameters, and 130 unique second parameters, and total of 260 unique strings used as function parameters.
3. All the function calls are located inside a single function (OnRegister, to be precise).

Edit: forgot to mention: GZDoom g3.6.0 - 2018-10-10 01:45:02 -0400 - SDL version
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript] Lost first string function parameter

Post by phantombeta »

Pretty sure this is a duplicate of this bug I reported.
What's going on here is that you're reaching the maximum amount of string contants the VM can store, not something with function parameters.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: [ZScript] Lost first string function parameter

Post by m8f »

Hmm. Probably it is. What confuses me is that in this example:
not-lost-parameter.pk3
(1.1 KiB) Downloaded 21 times
, which contains a function with 300 string constants, there is not such problem. The main difference that in not-lost-parameter.pk3, there is 300 calls of a function with one parameter instead of >128 calls of a function with two parameters.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Lost first string function parameter

Post by Graf Zahl »

The compiler is capable of handling more than 256 strings, but it looks like the generated code for some functions does not do it properly.

Well, looking at the disassembly it's obvious:

Code: Select all

00000800: 4d000300 param   a0                           ;0,3,0
00000804: 04000001 lk      s0,"1_128"                   ;0,0,1
00000808: 4d000200 param   s0                           ;0,2,0
0000080c: 04000101 lk      s0,"2_128"                   ;0,1,1
00000810: 4d000200 param   s0                           ;0,2,0
00000814: 50000300 call    [0000000E30B36370],3,0       ;0,3,0  
Strings are passed by reference into a function call, but the substitution logic for values > 255 is unaware of 'param's special needs. string parameters to functions are passed by reference and sSince both are loaded into the same register the first one will never reach its destination.
For a single parameter call this cannot happen because there's only one parameter.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: [ZScript] Lost first string function parameter

Post by m8f »

If this is not easy to fix (or not worth fixing), maybe a warning/error should be passed to the user?

I understand that such a big function is bad design, and must be divided into several separate functions.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Lost first string function parameter

Post by Graf Zahl »

This surely is fixable, this was just one special case where the default replacement does not work.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: [ZScript] Lost first string function parameter

Post by m8f »

Wow, thanks!
Post Reply

Return to “Closed Bugs [GZDoom]”