View Bug Report
Regarding the rare Stop on random page
Bug #: 898
File: Guild Store Search Extended [En/Fr/De]
Date: 06/27/14 03:38 PM
By: zgrssd
Status: Unconfirmed
Okay, did some tests with some d() message and events added. The issues is to about 95% in ld_timer.

Every once in a while it will fire the timer tick after ~50 ms instead of the planned time. And I used this way to set the timers so I know it was given the right values:
Code:
local remaining = GetTradingHouseCooldownRemaining()
ld_timer.addWithData("GSSE_Search", remaining,  gsse.doTradingHouseSearch, 1,{a,b,c})
d("Time left: " .. remaining)
It just seems to randomly ignore the time and fire it way early.

Propably best is to switch to CooldownUpdate in favor of timers. It will fire when the Cooldown reaches 0, so we can asume it is the right time for the next search.

RSS 2.0 Feed for Bug CommentsNotes Sort Options
By: zgrssd - 06/27/14 06:03 PM
Theory:
So far calllater was running synchonously in the UI thread.
With 1.2 this was changed so it now runs in a seperate thread, while the game itself deals with the associated plumbing.

This leads to a race condition with already existing timers where the timer is fired after setting only part of the data:
Code:
        --the tick check if the callback should be raised again happens before this line
        ld_timers[name].lastevent=GetGameTimeMilliseconds()
	ld_timers[name].millisecs=millisecs
	ld_timers[name].count=0
        --timespan in wich count is 0 but the old maxevents still is valid and we are inside the 2nd if block
	ld_timers[name].maxevents=maxevents
Possible solutions:
Clone the data before the 500 ms tick event processes them.
Modify the code to add the timer so it first builds them in a temp variable before adding it to the list.

The race condition was caused by modifying the timer already inside the list, instead of building one from scratch and then assigning it.
By: zgrssd - 06/28/14 02:55 AM
I was certain that changing the add and addWithData functions to this would solve the issue:
Code:
local function add(name, millisecs, callback, maxevents)
	if (name==nil) then name="tempTimerLD"..GetGameTimeMilliseconds() end
	
	local temp = { }
	
	temp.lastevent=GetGameTimeMilliseconds()
	temp.millisecs=millisecs
	temp.count=0
	temp.callback=callback
	temp.maxevents=maxevents
	temp.params=nil
	
	ld_timers[name] = temp
end

local function addWithData(name, millisecs, callback, maxevents,data)
	if (name==nil) then name="tempTimerLD"..GetGameTimeMilliseconds() end

	local temp = { }
	
	temp.lastevent=GetGameTimeMilliseconds()
	temp.millisecs=millisecs
	temp.count=0
	temp.callback=callback
	temp.maxevents=maxevents
	temp.params=data
	
	ld_timers[name] = temp
end
But there still is a error with the search starting to early. But now the windows is only < 30 ms isntead of <50
So I might have actually solved some issues with the rework. Just not the real one.
By: Sephiroth018 - 06/28/14 03:22 PM
I think I have found the real source of the problem, as I have also seen this with the addon PriceTrader and after digging through both addon's code and watching carefully what happened when, I saw it was always happening when changing the active guild. I also could reproduce that by manually doing a search and then trying to switch the guild while the search button was inactive.
So, long story short, the search delay now also affects SelectTradingHouseGuildId(int).
After modifying the code of GSSE to get and use the delay also when switching the guild, it worked (same for PriceTrader)
By: Sephiroth018 - 06/28/14 03:27 PM
If you want I can give you the modified code. I also added additional checks for the remaining delay time, just to be sure there is no problem when the delay function doesn't work correctly
By: brente72 - 07/02/14 10:40 AM
Hi Sephiroth018: is there some way you can post how to fix? I don't know when this GSSE will get updated to fix this but this issue is very frustrating. Does it just require a few lines of code changes to one of the .lua files?
By: Sephiroth018 - 07/02/14 12:43 PM
I decided today I will post the fix here and in the comments section, since I got no reply for some time now. The fix can be found under https://onedrive.live.com/redir?resid=19BA2FEDD38D5C57!2743&authkey=!AMUnaINfzbN58rg&ithint=file%2c.zip and contains the whole GSSE addon. Just copy it over your existing GSSE folder.

Please be aware that my fix also removes the option to define a time between searches yourself and instead uses the new function from the API to get the remaining time till the next allowed search. So normally the time between searches is 4 seconds (3 is the normal time after a search and I add a second to the return value of the function, just to be sure).
By: Sephiroth018 - 07/02/14 12:48 PM
The fix is also available under the following link, since onedrive seems to be having issues at the moment: https://docs.google.com/file/d/0B292oiKAcbWpZFltYzdfaUxucDg/edit
By: brente72 - 07/02/14 01:49 PM
Thanks Seph! I had just figured out how to fix this myself when you posted, but I like your fix better. Works great!