Thread Tools Display Modes
09/26/16, 04:17 PM   #1
code65536
AddOn Author - Click to view addons
Join Date: Mar 2016
Posts: 21
[fixed] Faulty code in ZO_SortHeaderGroup:OnHeaderClicked

There is a problem in the ZO_SortHeaderGroup:OnHeaderClicked function (found in \esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua), specifically, with the following line of code:

Code:
        self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
The "condition and a or b" shorthand in Lua is subject to one crucial caveat: the "a" term must never be nil or false. If it is, then "b" will always be used, regardless of what "condition" evaluates to.

In this case, since the sort directions are stored as either true or false, this line of code returns the incorrect result if resetSortDir is true and initialDirection is down (false). This code must be replaced with if-then longhand (reversing the condition and swapping a and b will suffer the same problem).

You can see this bug in action if you try to use SelectAndResetSortForKey on a column that has a downward initial sort direction.

(Also, it might be a good idea to audit the code for more instances of these "condition and a or b" shorthands--this is a subtle and easily-missed error, and there could be other places that might have similar problems.)
 
09/26/16, 06:11 PM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
For bugs, consider /bug

It saves jobs & process
 
09/27/16, 08:00 AM   #3
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
I feel like this was reported before but I forgot to fix it. Well, it's fixed now. It will be part of the next package.
 
09/27/16, 06:57 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by ZOS_ChipHilseberg View Post
I feel like this was reported before but I forgot to fix it. Well, it's fixed now. It will be part of the next package.
Yes, I've reported that here
 

ESOUI » Developer Discussions » Bug Reports » [fixed] Faulty code in ZO_SortHeaderGroup:OnHeaderClicked

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off