Jump to content

[bug] UI bug with soundset sorting


DavidW

Recommended Posts

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).

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...