These are existing bugs, but quick to fix:
Advanced setup.lua
line 827 should read: "for i = numPlayers, GameDefines.MAX_MAJOR_CIVS - 1 do" (it's missing the -1)
TradeLogic.lua
line 2133 should read: "for i = 0, GameDefines.MAX_CIV_PLAYERS - 1 do" (it's missing the -1)
PlotMouseoverInclude.lua
line 258 should read: "for i = 0, numUnits - 1 do" (it's missing the -1)
CivilopediaScreen.lua
line 2461 should read: "if thisTech.AllowEmbassyTradingAllowed then" (y, not ies)
ReligionOverview.lua
lines 444 & 521 should read: "if (pPlayer:IsEverAlive()) then" rather than ":IsAlive()" or commented out
UniqueBonuses.lua
missing a line which reads: "local nullOffset = Vector2( 0, 0 );"
With regards to the problematic popup queue management, noticed that:
1/ Demographics.lua, GenericPopup.lua, and VictoryProgress.lua are all lack the call to "Events.SerialEventGameMessagePopupShown"
2/ TechPopup.lua is calling "Events.SerialEventGameMessagePopupProcessed" rather than "Events.SerialEventGameMessagePopupProcessed.CallImmediate"
3/ the call to "Events.SerialEventGameMessagePopupProcessed.CallImmediate" is done by the ShowHideHandler upon hiding the popup, but the problem with this logic is that popups may be hidden by the game engine when encountering a higher priority popup e.g. upon function key press, once the higher priority one is closed the lower priority one is restored, so Events.SerialEventGameMessagePopupProcessed.CallImmediate gets called again for no reason. And actually both cases can occur, because e.g. when clicking with the mouse on toppanel item the popup has a low priority and does not get displayed until the one called with the function key is closed... And when pressing function keys in sequence it can quickly become a mess
it's actually surprising the game engine gets popups stuck so rarely