1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix Result of processed Request was written to invalid (non existent) ResultQueue if requesting thread timed out before

This commit is contained in:
sapier 2013-11-14 18:30:43 +01:00 committed by kwolekr
parent eadc943159
commit b2d9205796
3 changed files with 92 additions and 86 deletions

View file

@ -477,21 +477,24 @@ public:
else
{
// We're gonna ask the result to be put into here
ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
static ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
// Throw a request in
m_get_clientcached_queue.add(name, 0, 0, &result_queue);
try{
// Wait result for a second
GetResult<std::string, ClientCached*, u8, u8>
while(true) {
// Wait result for a second
GetResult<std::string, ClientCached*, u8, u8>
result = result_queue.pop_front(1000);
// Check that at least something worked OK
assert(result.key == name);
// Return it
return result.item;
if (result.key == name) {
return result.item;
}
}
}
catch(ItemNotFoundException &e)
{
errorstream<<"Waiting for clientcached timed out."<<std::endl;
errorstream<<"Waiting for clientcached " << name << " timed out."<<std::endl;
return &m_dummy_clientcached;
}
}
@ -560,7 +563,7 @@ public:
// Ensure that the "" item (the hand) always has ToolCapabilities
if(def.name == "")
assert(def.tool_capabilities != NULL);
if(m_item_definitions.count(def.name) == 0)
m_item_definitions[def.name] = new ItemDefinition(def);
else