Skip to content

Commit b2d9205

Browse files
sapierkwolekr
sapier
authored andcommittedNov 17, 2013
Fix Result of processed Request was written to invalid (non existent) ResultQueue if requesting thread timed out before
1 parent eadc943 commit b2d9205

File tree

3 files changed

+92
-86
lines changed

3 files changed

+92
-86
lines changed
 

‎src/itemdef.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,24 @@ class CItemDefManager: public IWritableItemDefManager
477477
else
478478
{
479479
// We're gonna ask the result to be put into here
480-
ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
480+
static ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
481+
481482
// Throw a request in
482483
m_get_clientcached_queue.add(name, 0, 0, &result_queue);
483484
try{
484-
// Wait result for a second
485-
GetResult<std::string, ClientCached*, u8, u8>
485+
while(true) {
486+
// Wait result for a second
487+
GetResult<std::string, ClientCached*, u8, u8>
486488
result = result_queue.pop_front(1000);
487-
// Check that at least something worked OK
488-
assert(result.key == name);
489-
// Return it
490-
return result.item;
489+
490+
if (result.key == name) {
491+
return result.item;
492+
}
493+
}
491494
}
492495
catch(ItemNotFoundException &e)
493496
{
494-
errorstream<<"Waiting for clientcached timed out."<<std::endl;
497+
errorstream<<"Waiting for clientcached " << name << " timed out."<<std::endl;
495498
return &m_dummy_clientcached;
496499
}
497500
}
@@ -560,7 +563,7 @@ class CItemDefManager: public IWritableItemDefManager
560563
// Ensure that the "" item (the hand) always has ToolCapabilities
561564
if(def.name == "")
562565
assert(def.tool_capabilities != NULL);
563-
566+
564567
if(m_item_definitions.count(def.name) == 0)
565568
m_item_definitions[def.name] = new ItemDefinition(def);
566569
else

‎src/shader.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -417,29 +417,31 @@ u32 ShaderSource::getShaderId(const std::string &name)
417417
if(get_current_thread_id() == m_main_thread){
418418
return getShaderIdDirect(name);
419419
} else {
420-
infostream<<"getShaderId(): Queued: name=\""<<name<<"\""<<std::endl;
420+
/*errorstream<<"getShaderId(): Queued: name=\""<<name<<"\""<<std::endl;*/
421421

422422
// We're gonna ask the result to be put into here
423-
ResultQueue<std::string, u32, u8, u8> result_queue;
423+
424+
static ResultQueue<std::string, u32, u8, u8> result_queue;
424425

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

428-
infostream<<"Waiting for shader from main thread, name=\""
429-
<<name<<"\""<<std::endl;
429+
/* infostream<<"Waiting for shader from main thread, name=\""
430+
<<name<<"\""<<std::endl;*/
430431

431432
try{
432-
// Wait result for a second
433-
GetResult<std::string, u32, u8, u8>
433+
while(true) {
434+
// Wait result for a second
435+
GetResult<std::string, u32, u8, u8>
434436
result = result_queue.pop_front(1000);
435437

436-
// Check that at least something worked OK
437-
assert(result.key == name);
438-
439-
return result.item;
438+
if (result.key == name) {
439+
return result.item;
440+
}
441+
}
440442
}
441443
catch(ItemNotFoundException &e){
442-
infostream<<"Waiting for shader timed out."<<std::endl;
444+
errorstream<<"Waiting for shader " << name << " timed out."<<std::endl;
443445
return 0;
444446
}
445447
}
@@ -541,10 +543,10 @@ void ShaderSource::processQueue()
541543
GetRequest<std::string, u32, u8, u8>
542544
request = m_get_shader_queue.pop();
543545

544-
/*infostream<<"ShaderSource::processQueue(): "
546+
/**errorstream<<"ShaderSource::processQueue(): "
545547
<<"got shader request with "
546548
<<"name=\""<<request.key<<"\""
547-
<<std::endl;*/
549+
<<std::endl;**/
548550

549551
m_get_shader_queue.pushResult(request,getShaderIdDirect(request.key));
550552
}
@@ -594,7 +596,7 @@ void ShaderSource::onSetConstants(video::IMaterialRendererServices *services,
594596
setter->onSetConstants(services, is_highlevel);
595597
}
596598
}
597-
599+
598600
ShaderInfo generate_shader(std::string name, IrrlichtDevice *device,
599601
video::IShaderConstantSetCallBack *callback,
600602
SourceShaderCache *sourcecache)

0 commit comments

Comments
 (0)
Please sign in to comment.