Issue information

Issue ID
#8008
Status
Fixed
Severity
None
Started
KeyWorld
Feb 6, 2014 0:04
Last Post
Haru
Mar 6, 2014 1:13
Confirmation
N/A

KeyWorld - Feb 6, 2014 0:04

Git version: 8fb2b31e8de73872baddc3d983a4eea5c359329d

Maybe related to the last script core update (array size limit), I found a bug while trying to copy a referenced array:

Script:[code=auto:0] function script test { // Get array size and display it .@count = getarraysize(getarg(0)); debugmes "array size: " + .@count + ";"; // Copy argument to .@array copyarray .@array, getarg(0), .@count; // Display getarg(0) content debugmes "----------------------------------"; debugmes "getarg(0) :"; for (.@i = 0; .@i < .@count; .@i++) { debugmes getelementofarray(getarg(0), .@i); } // Display .@array content debugmes "----------------------------------"; debugmes ".@array:"; for (.@i = 0; .@i < .@count; .@i++) { debugmes .@array[.@i]; } } - script _ -1,{ OnInit: .@count = 20; for (.@i = 0; .@i < .@count; ++.@i) { .@array[.@i] = rand(10000); } callfunc("test", .@array); } [/code]


And logs:[code=auto:0] [Debug]: script debug : 0 110343621 : array size: 20; [Debug]: script debug : 0 110343621 : ---------------------------------- [Debug]: script debug : 0 110343621 : getarg(0) : [Debug]: script debug : 0 110343621 : 6390 [Debug]: script debug : 0 110343621 : 9996 [Debug]: script debug : 0 110343621 : 9025 [Debug]: script debug : 0 110343621 : 8314 [Debug]: script debug : 0 110343621 : 7550 [Debug]: script debug : 0 110343621 : 2312 [Debug]: script debug : 0 110343621 : 8149 [Debug]: script debug : 0 110343621 : 3863 [Debug]: script debug : 0 110343621 : 6211 [Debug]: script debug : 0 110343621 : 1452 [Debug]: script debug : 0 110343621 : 8013 [Debug]: script debug : 0 110343621 : 7703 [Debug]: script debug : 0 110343621 : 2360 [Debug]: script debug : 0 110343621 : 1450 [Debug]: script debug : 0 110343621 : 6760 [Debug]: script debug : 0 110343621 : 2451 [Debug]: script debug : 0 110343621 : 9679 [Debug]: script debug : 0 110343621 : 6518 [Debug]: script debug : 0 110343621 : 232 [Debug]: script debug : 0 110343621 : 1001 [Debug]: script debug : 0 110343621 : ---------------------------------- [Debug]: script debug : 0 110343621 : .@array: [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [Debug]: script debug : 0 110343621 : 0 [/code]

Dastgir Pojee - Feb 6, 2014 3:07

Havent tested, but according to doc,
it should be like
copyarray @array2[0],@array[2],2;
You are not putting brackets.

KeyWorld - Feb 6, 2014 7:21

Bracket is optional.
But yeah I also tested with getelementofarray and it's the same result.

AnnieRuru - Feb 6, 2014 14:46

if you report here, then its the same with rathena
because when I wrote that script with rathena emulator
[url="http://rathena.org/board/pastebin/jdsshuef1ic/"]http://rathena.org/board/pastebin/jdsshuef1ic/[/url]
I used $@tmp_array[code=auto:0]copyarray $@tmp_array, getarg(2), .@size;[/code][code=auto:0]function script test { // Get array size and display it .@count = getarraysize(getarg(0)); debugmes "array size: " + .@count + ";"; // Copy argument to $@array copyarray $@tmp_aray, getarg(0), .@count; // Display getarg(0) content debugmes "----------------------------------"; debugmes "getarg(0) :"; for (.@i = 0; .@i < .@count; .@i++) { debugmes getelementofarray(getarg(0), .@i); } // Display $@array content debugmes "----------------------------------"; debugmes "$@array:"; for (.@i = 0; .@i < .@count; .@i++) { debugmes $@tmp_aray[.@i]; } } - script _ -1,{ OnInit: .@count = 20; for (.@i = 0; .@i < .@count; ++.@i) { .@array[.@i] = rand(10000); } callfunc("test", .@array); }[/code]this will work

although, I have no objections if hercules developer wants to fix this
because this bug also happens in rathena

Haru - Feb 6, 2014 19:29

It happens because the arrays have the same name :x

AnnieRuru - Feb 6, 2014 19:33

sry double post
but I think the problem lies somewhere else[code=auto:0]function script test { // Get array size and display it .@count = getarraysize(getarg(0)); debugmes "array size: " + .@count + ";"; // Copy argument to $@array copyarray .@array_, getarg(0), .@count; // Display getarg(0) content debugmes "----------------------------------"; debugmes "getarg(0) :"; for (.@i = 0; .@i < .@count; .@i++) { debugmes getelementofarray(getarg(0), .@i); } // Display $@array content debugmes "----------------------------------"; debugmes ".@array:"; for (.@i = 0; .@i < .@count; .@i++) { debugmes .@array_[.@i]; } } - script _ -1,{ OnInit: .@count = 20; for (.@i = 0; .@i < .@count; ++.@i) { .@array[.@i] = rand(10000); } callfunc("test", .@array); }[/code]I just change .@array into .@array_
now it works o.O

EDIT : AHHH ~ !! Haru post faster than me

This post has been edited by AnnieRuru on Feb 6, 2014 19:34

KeyWorld - Feb 7, 2014 9:39

[quote name="Haru" timestamp="1391714979"]
It happens because the arrays have the same name :x[/quote]

Seems like it's the problem, but should not occur with .@array since they do not share the same scope.

Haru - Feb 8, 2014 3:37

Yes, it *should* not occur, but it does because of a bug with scope handling by the copyarray function. I have a fix ready, but I want to test it a little, and possibly doublecheck if there's anything else that suffers the same problem. Commit is on my fork, at the tip of the copyarray-ref-fix branch, in case you want to see it. [url="https://github.com/MishimaHaruna/Hercules/commits/copyarray-ref-fix"]https://github.com/MishimaHaruna/Hercules/commits/copyarray-ref-fix[/url]

Haru - Mar 6, 2014 1:13

Fixed in [url="https://github.com/HerculesWS/Hercules/commit/a1918e7"]https://github.com/HerculesWS/Hercules/commit/a1918e7[/url]