Itemsort stack overflow.
I added a piece of code to my modification of cargbags_gnomed borrowed from ouf_nivaya if I remember correctly.
The code works fine, but the first login of a character (first login ever with no wtf/savedvariables files created etc) I get a stack overflow from the line: (5) local pe = t[floor((l+r)/2)][c] -- pivot element Anyone know why? Code:
local function QuickSort(tTable) |
This happens a lot when you have a function call itself recursively.
This is what QS_int() seems to be doing. My advise is find a way to write a formula or put the code in a loop until it comes out with what you want it to do. Edit1: Hopefully, I successfully integrated a loop in the code to stop the recursive calling and produce the same result. I'm still not sure what the code is supposed to do, but it should be fixed now. It'll either work or be thrown into an infinite loop. *shrugs* Edit2: Revised the code again, discovered a possibility that wouldn't have resulted in the code running exactly the same way as OP. Edit3: Hopefully the last revision now that I've worked around with the code a little. I'm still seeing a lot of possibilities for infinite loops, for example, any time pe is nil. This might be what caused the problem in the first place. Added an else break clause to prevent it. Edit4: Corrected variable contamination before the last check. lua Code:
|
I'm guessing I'm supposed to change line 4 to do instead of then. However, then resulted in an error expecting a do, and a do resulted in an endless load and wow not responding.
|
This is one reason I went back to using table.sort() with a custom check function. I highly doubt any code written in Lua would be any faster than its C library code.
This is a rough draft for a function that should do the same thing. lua Code:
|
|
The code itself is just a function declaration with isolated upvalues, it can be pasted practically anywhere.
The syntax is similar to table.sort() for the exception it can take an index for what values to compare in a 2d table. This however doesn't support defining your own check function. For example, when you're sorting for quality, the call would look like this (assuming the quality is index 2): Code:
SortByElement(tTable,2) I can get to work on a complete function rewrite of QuickSort(). You do want to sort by indicies 2 then 1, right? |
Go ahead and replace the entire definition of QuickSort() on line 140 with this.
lua Code:
|
The code returns no errors, but the sorting is weird.
Old Code: Your code / New code: |
Do you have the full addon available for download so I can try to do some debugging?
Edit: Nevermind, I think I found the problem. I corrected the QuickSort() replacement code, try it again. |
v1 not a value or something :P
I'm at school atm but as far as I remember the v1 in line1 returned an error as nil or non existant or something of the sorts. |
I added a condition for if v1 or v2 is nil, shouldn't happen, but I've seen it on rare occasion. I've also seen the sort function complain about the return from the check function too.
|
Interface\AddOns\cargBags_Shakes\layout.lua:150: invalid order function for sorting
Count: 2 That line is QuickSort=function(tbl) table.sort(tbl,func); end |
Quote:
Code:
invalid order function for sorting |
It's a glitch with table.sort() that's been a thorn in my side ever since the beginning. It's supposed to take a boolean return value from the comparison function, but it isn't exactly stable and throws errors on a lot of valid code.
|
Quote:
|
You can use a tail call to reuse the stack entry instead of creating a new one like you normally would:
Code:
function a() a() end a() -- fills the stack |
Quote:
From what understanding I make out of that, the sort function doesn't like being told not to swap values for the reason both values are equal? |
Quote:
lua Code:
I wrote that recursive sorting function because I didn't find a way to use table.sort with my data structure. I was also aware of the stack overflow errors it produced but I didn't find a way around it. So I hope it's ok if I use your code as a replacement in cargbags_Nivaya too? |
Quote:
*EDIT* I added the code from nivaya so it works fine now. Thanks a lot to all parties involved ;) However, is it possible to add a third sorting? Now it's quality, itemid. Is it possible to add itemcount as a third sort? And also, how would I go about reversing the quality sort? Now its green > blue > epic. I want to see how it looks the other way. Its not very important though so don't stress yourself if it's hard ;P |
Quote:
lua Code:
|
All times are GMT -6. The time now is 02:19 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI