2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 5d09be1f authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Fixed missing/wrong deregistration of GeometryXdTransferFcuntionEditors when...

Fixed missing/wrong deregistration of GeometryXdTransferFcuntionEditors when their widgets are closed (and hence the GL contexts destroyed)
parent 505b37e3
...@@ -83,8 +83,11 @@ namespace campvis { ...@@ -83,8 +83,11 @@ namespace campvis {
Geometry1DTransferFunction* gtf = static_cast<Geometry1DTransferFunction*>(_transferFunction); Geometry1DTransferFunction* gtf = static_cast<Geometry1DTransferFunction*>(_transferFunction);
gtf->s_geometryCollectionChanged.disconnect(this); gtf->s_geometryCollectionChanged.disconnect(this);
// TODO: this needs to be done, but we can not ensure that GLJobProc is still existant during deconstruction...
//GLJobProc.deregisterContext(_canvas); if (OpenGLJobProcessor::isInited())
GLJobProc.deregisterContext(_canvas);
if (tgt::GlContextManager::isInited())
tgt::GlContextManager::getRef().removeContext(_canvas);
} }
void Geometry1DTransferFunctionEditor::updateWidgetFromProperty() { void Geometry1DTransferFunctionEditor::updateWidgetFromProperty() {
......
...@@ -79,8 +79,11 @@ namespace campvis { ...@@ -79,8 +79,11 @@ namespace campvis {
Geometry2DTransferFunction* gtf = static_cast<Geometry2DTransferFunction*>(_transferFunction); Geometry2DTransferFunction* gtf = static_cast<Geometry2DTransferFunction*>(_transferFunction);
gtf->s_geometryCollectionChanged.disconnect(this); gtf->s_geometryCollectionChanged.disconnect(this);
// TODO: this needs to be done, but we can not ensure that GLJobProc is still existant during deconstruction...
//GLJobProc.deregisterContext(_canvas); if (OpenGLJobProcessor::isInited())
GLJobProc.deregisterContext(_canvas);
if (tgt::GlContextManager::isInited())
tgt::GlContextManager::getRef().removeContext(_canvas);
} }
void Geometry2DTransferFunctionEditor::updateWidgetFromProperty() { void Geometry2DTransferFunctionEditor::updateWidgetFromProperty() {
......
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
namespace campvis { namespace campvis {
OpenGLJobProcessor::OpenGLJobProcessor() OpenGLJobProcessor::OpenGLJobProcessor()
: _currentContext(0)
{ {
_pause = 0; _pause = 0;
_currentContext = 0;
} }
OpenGLJobProcessor::~OpenGLJobProcessor() { OpenGLJobProcessor::~OpenGLJobProcessor() {
...@@ -77,8 +77,8 @@ namespace campvis { ...@@ -77,8 +77,8 @@ namespace campvis {
tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::const_accessor a; tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::const_accessor a;
if (!_contextQueueMap.find(a, context)) { if (!_contextQueueMap.find(a, context)) {
tgtAssert(false, "Should not reach this: Did not find context in contextQueueMap!"); //tgtAssert(false, "Should not reach this: Did not find context in contextQueueMap!");
break; continue;
} }
// avoid expensive context-switches for contexts without pending jobs. // avoid expensive context-switches for contexts without pending jobs.
...@@ -214,11 +214,14 @@ namespace campvis { ...@@ -214,11 +214,14 @@ namespace campvis {
} }
void OpenGLJobProcessor::deregisterContext(tgt::GLCanvas* context) { void OpenGLJobProcessor::deregisterContext(tgt::GLCanvas* context) {
tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::const_accessor a; tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::accessor a;
if (_contextQueueMap.find(a, context)) { if (_contextQueueMap.find(a, context)) {
delete a->second; delete a->second;
_contextQueueMap.erase(a); _contextQueueMap.erase(a);
} }
if (_currentContext == context)
_currentContext.compare_and_swap(0, context);
} }
tgt::GLCanvas* OpenGLJobProcessor::iKnowWhatImDoingGetArbitraryContext() { tgt::GLCanvas* OpenGLJobProcessor::iKnowWhatImDoingGetArbitraryContext() {
......
...@@ -183,7 +183,7 @@ namespace campvis { ...@@ -183,7 +183,7 @@ namespace campvis {
tbb::atomic<int> _pause; tbb::atomic<int> _pause;
std::condition_variable _evaluationCondition; ///< conditional wait to be used when there are currently no jobs to process std::condition_variable _evaluationCondition; ///< conditional wait to be used when there are currently no jobs to process
tgt::GLCanvas* _currentContext; ///< current active OpenGL context tbb::atomic<tgt::GLCanvas*> _currentContext; ///< current active OpenGL context
}; };
} }
......
...@@ -21,6 +21,7 @@ namespace tgt { ...@@ -21,6 +21,7 @@ namespace tgt {
GLCanvas* GlContextManager::getContextByKey(const std::string& key) { GLCanvas* GlContextManager::getContextByKey(const std::string& key) {
tbb::mutex::scoped_lock lock(_localMutex);
std::map<std::string, GLCanvas*>::iterator it = _contexts.find(key); std::map<std::string, GLCanvas*>::iterator it = _contexts.find(key);
if (it != _contexts.end()) if (it != _contexts.end())
return it->second; return it->second;
...@@ -78,5 +79,16 @@ namespace tgt { ...@@ -78,5 +79,16 @@ namespace tgt {
setCurrent(context); setCurrent(context);
} }
void GlContextManager::removeContext(GLCanvas* context) {
_currentContext = 0;
tbb::mutex::scoped_lock lock(_localMutex);
for (std::map<std::string, GLCanvas*>::iterator it = _contexts.begin(); it != _contexts.end(); ++it) {
if (it->second == context) {
_contexts.erase(it);
break;
}
}
}
} }
...@@ -66,6 +66,13 @@ namespace tgt { ...@@ -66,6 +66,13 @@ namespace tgt {
const GLCanvas::Buffers buffers = GLCanvas::RGBADD, const GLCanvas::Buffers buffers = GLCanvas::RGBADD,
bool shared = true) = 0; bool shared = true) = 0;
/**
* Removes the OpenGL context \a context from the list of managed contexts.
* \param context Context to remove.
*/
virtual void removeContext(GLCanvas* context);
/** /**
* Returns the OpenGL context with the given key \a key, 0 if no such context exists. * Returns the OpenGL context with the given key \a key, 0 if no such context exists.
* \param key Key of the context to return. * \param key Key of the context to return.
...@@ -111,6 +118,8 @@ namespace tgt { ...@@ -111,6 +118,8 @@ namespace tgt {
GLCanvas* _currentContext; ///< Current active OpenGL context GLCanvas* _currentContext; ///< Current active OpenGL context
tbb::mutex _glMutex; ///< Mutex protecting OpenGL for multi-threaded access tbb::mutex _glMutex; ///< Mutex protecting OpenGL for multi-threaded access
tbb::mutex _localMutex; ///< local mutex to prodect _contexts
static GlContextManager* singletonClass_; static GlContextManager* singletonClass_;
}; };
......
...@@ -18,6 +18,7 @@ namespace tgt { ...@@ -18,6 +18,7 @@ namespace tgt {
// FIXME: rethink this concept of unique IDs // FIXME: rethink this concept of unique IDs
//tgtAssert(_contexts.find(key) == _contexts.end(), "A context with the same key already exists!"); //tgtAssert(_contexts.find(key) == _contexts.end(), "A context with the same key already exists!");
tbb::mutex::scoped_lock localLock(_localMutex);
tbb::mutex::scoped_lock lock(_glMutex); tbb::mutex::scoped_lock lock(_glMutex);
QtThreadedCanvas* toReturn = new QtThreadedCanvas(title, size, buffers, 0, shared); QtThreadedCanvas* toReturn = new QtThreadedCanvas(title, size, buffers, 0, shared);
_contexts.insert(std::make_pair(key, toReturn)); _contexts.insert(std::make_pair(key, toReturn));
......
...@@ -43,12 +43,12 @@ namespace campvis { ...@@ -43,12 +43,12 @@ namespace campvis {
VirtualMirrorGeometryGenerator::VirtualMirrorGeometryGenerator() VirtualMirrorGeometryGenerator::VirtualMirrorGeometryGenerator()
: AbstractProcessor() : AbstractProcessor()
, p_mirrorID("geometryID", "Output Geometry ID", "mirror", DataNameProperty::WRITE) , p_mirrorID("geometryID", "Output Geometry ID", "mirror", DataNameProperty::WRITE)
, p_mirrorCenter("mirrorCenter", "Mirror Center", tgt::vec3(1.f), tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(0.1f)) , p_mirrorCenter("mirrorCenter", "Mirror Center", tgt::vec3(1.f), tgt::vec3(-1000.f), tgt::vec3(1000.f), tgt::vec3(0.1f))
, p_mirrorNormal("mirrorNormal", "Mirror Normal", tgt::vec3(0.f, 1.f, 0.f), tgt::vec3(-1.f), tgt::vec3(1.f), , p_mirrorNormal("mirrorNormal", "Mirror Normal", tgt::vec3(0.f, 1.f, 0.f), tgt::vec3(-1.f), tgt::vec3(1.f),
tgt::vec3(0.001f), tgt::ivec3(3), AbstractProcessor::VALID) tgt::vec3(0.001f), tgt::ivec3(3), AbstractProcessor::VALID)
, p_size("mirrorSize", "Mirror Size", 4.0f, 0.1f, 1000.0f, 0.1f) , p_size("mirrorSize", "Mirror Size", 4.0f, 0.1f, 1000.0f, 0.1f)
, p_numVertices("Roundness", "Roundness", 16, 4, 128) , p_numVertices("Roundness", "Roundness", 16, 4, 128)
, p_poi("poi", "Point of Interest", tgt::vec3::zero, tgt::vec3(-100.f), tgt::vec3(1000.f), tgt::vec3(0.1f)) , p_poi("poi", "Point of Interest", tgt::vec3::zero, tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(0.1f))
, p_camera("camera", "Camera") , p_camera("camera", "Camera")
{ {
addProperty(&p_mirrorID); addProperty(&p_mirrorID);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment