Skip to content

Commit

Permalink
Fix Result of processed Request was written to invalid (non existent)…
Browse files Browse the repository at this point in the history
… ResultQueue if requesting thread timed out before
  • Loading branch information
sapier authored and kwolekr committed Nov 17, 2013
1 parent eadc943 commit b2d9205
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 86 deletions.
21 changes: 12 additions & 9 deletions src/itemdef.cpp
Expand Up @@ -477,21 +477,24 @@ class CItemDefManager: public IWritableItemDefManager
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;
}
}
Expand Down Expand Up @@ -560,7 +563,7 @@ class CItemDefManager: public IWritableItemDefManager
// 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
Expand Down
30 changes: 16 additions & 14 deletions src/shader.cpp
Expand Up @@ -417,29 +417,31 @@ u32 ShaderSource::getShaderId(const std::string &name)
if(get_current_thread_id() == m_main_thread){
return getShaderIdDirect(name);
} else {
infostream<<"getShaderId(): Queued: name=\""<<name<<"\""<<std::endl;
/*errorstream<<"getShaderId(): Queued: name=\""<<name<<"\""<<std::endl;*/

// We're gonna ask the result to be put into here
ResultQueue<std::string, u32, u8, u8> result_queue;

static ResultQueue<std::string, u32, u8, u8> result_queue;

// Throw a request in
m_get_shader_queue.add(name, 0, 0, &result_queue);

infostream<<"Waiting for shader from main thread, name=\""
<<name<<"\""<<std::endl;
/* infostream<<"Waiting for shader from main thread, name=\""
<<name<<"\""<<std::endl;*/

try{
// Wait result for a second
GetResult<std::string, u32, u8, u8>
while(true) {
// Wait result for a second
GetResult<std::string, u32, u8, u8>
result = result_queue.pop_front(1000);

// Check that at least something worked OK
assert(result.key == name);

return result.item;
if (result.key == name) {
return result.item;
}
}
}
catch(ItemNotFoundException &e){
infostream<<"Waiting for shader timed out."<<std::endl;
errorstream<<"Waiting for shader " << name << " timed out."<<std::endl;
return 0;
}
}
Expand Down Expand Up @@ -541,10 +543,10 @@ void ShaderSource::processQueue()
GetRequest<std::string, u32, u8, u8>
request = m_get_shader_queue.pop();

/*infostream<<"ShaderSource::processQueue(): "
/**errorstream<<"ShaderSource::processQueue(): "
<<"got shader request with "
<<"name=\""<<request.key<<"\""
<<std::endl;*/
<<std::endl;**/

m_get_shader_queue.pushResult(request,getShaderIdDirect(request.key));
}
Expand Down Expand Up @@ -594,7 +596,7 @@ void ShaderSource::onSetConstants(video::IMaterialRendererServices *services,
setter->onSetConstants(services, is_highlevel);
}
}

ShaderInfo generate_shader(std::string name, IrrlichtDevice *device,
video::IShaderConstantSetCallBack *callback,
SourceShaderCache *sourcecache)
Expand Down

0 comments on commit b2d9205

Please sign in to comment.