DavidW Posted July 17, 2022 Share Posted July 17, 2022 There is a rather subtle bug in the UI code to sort custom soundsets, present on all four of BGEE, SoD, BG2EE, IWDEE. The soundsets are sorted by the lua function compareCustomSounds (in ui.menu), which is as follows: function compareCustomSound(s1, s2) -- DEFAULT, then normal alphabetically, then AoN alphabetically (result must be strictly less than) if (s1.sound == "DEFAULT") then return s2.sound ~= "DEFAULT"; elseif (string.sub(s1.sound, 1, 4) == "BDTP") then if (string.sub(s2.sound, 1, 4) ~= "BDTP") then return false; end elseif (string.sub(s2.sound, 1, 4) == "BDTP") then return true; end return s1.sound < s2.sound; end But this doesn't quite do what it's supposed to do, at least if there are any soundsets with filenames alphabetically preceding DEFAULT. Suppose you add a soundset 'BREAKS'. Then compareCustomSound will deliver DEFAULT>BREAKS, but also BREAKS>DEFAULT. lua's table.sort algorithm demands (reasonably enough) that its sort function defines a total order, so it sulks and stops sorting the sound table, leaving a mess. (The problem occurs because although the function forces DEFAULT>anything, it doesn't force anything<DEFAULT - it just resorts to alphabetical order.) As it happens, this doesn't occur in unmodded play because the default soundsets all have names alphabetically later than DEFAULT. But it could easily occur in a mod or just if a user adds their own soundset. This version works: function compareCustomSound(s1, s2) -- DEFAULT, then normal alphabetically, then AoN alphabetically (result must be strictly less than) if (s1.sound == "DEFAULT") then return s2.sound ~= "DEFAULT"; elseif (s2.sound == "DEFAULT") then return false; elseif (string.sub(s1.sound, 1, 4) == "BDTP") then if (string.sub(s2.sound, 1, 4) ~= "BDTP") then return false; end elseif (string.sub(s2.sound, 1, 4) == "BDTP") then return true; end return s1.sound < s2.sound; end I'm about to upload a fix to the fixpack (in files/tph/dw/ui_fixes.tph). Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.