Code: Select all
#Requires AutoHotkey v2.0-
test := "
(
aa
aaa
bbb
cccc
dddd
eeeee
fff
)"
loop 10
my_func(test)
my_func(test) {
test := Sort(test,,_sort)
msgbox test
_sort(first, second, offset) { ; sorts by string length (longest string on top)
If StrLen(first) > StrLen(second)
return -1
Else if StrLen(first) < StrLen(second)
return 1
Else return 0
}
}
For me, I get invalid memory read/write error every time on the 3rd iteration. This only happens when using a custom sorting function. If I move the sort function out so it is not a closure func obj, it still happens.
Error Message:
Code: Select all
---------------------------
test.ahk
---------------------------
Critical Error: Invalid memory read/write.
Line#
004: test := "aa
aaa
bbb
cccc
dddd
eeeee
fff"
017: Loop 10
018: my_func(test)
020: {
---> 021: test := Sort(test,,_sort)
022: msgbox(test)
024: {
025: If StrLen(first) > StrLen(second)
026: Return -1
027: Else
027: If StrLen(first) < StrLen(second)
028: Return 1
The program is now unstable and will exit.
---------------------------
OK
---------------------------