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 {
Geometry1DTransferFunction* gtf = static_cast<Geometry1DTransferFunction*>(_transferFunction);
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() {
......
......@@ -79,8 +79,11 @@ namespace campvis {
Geometry2DTransferFunction* gtf = static_cast<Geometry2DTransferFunction*>(_transferFunction);
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() {
......
......@@ -38,9 +38,9 @@
namespace campvis {
OpenGLJobProcessor::OpenGLJobProcessor()
: _currentContext(0)
{
_pause = 0;
_currentContext = 0;
}
OpenGLJobProcessor::~OpenGLJobProcessor() {
......@@ -77,8 +77,8 @@ namespace campvis {
tbb::concurrent_hash_map<tgt::GLCanvas*, PerContextJobQueue*>::const_accessor a;
if (!_contextQueueMap.find(a, context)) {
tgtAssert(false, "Should not reach this: Did not find context in contextQueueMap!");
break;
//tgtAssert(false, "Should not reach this: Did not find context in contextQueueMap!");
continue;
}
// avoid expensive context-switches for contexts without pending jobs.
......@@ -214,11 +214,14 @@ namespace campvis {
}
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)) {
delete a->second;
_contextQueueMap.erase(a);
}
if (_currentContext == context)
_currentContext.compare_and_swap(0, context);
}
tgt::GLCanvas* OpenGLJobProcessor::iKnowWhatImDoingGetArbitraryContext() {
......
......@@ -183,7 +183,7 @@ namespace campvis {
tbb::atomic<int> _pause;
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 {
GLCanvas* GlContextManager::getContextByKey(const std::string& key) {
tbb::mutex::scoped_lock lock(_localMutex);
std::map<std::string, GLCanvas*>::iterator it = _contexts.find(key);
if (it != _contexts.end())
return it->second;
......@@ -42,7 +43,7 @@ namespace tgt {
void GlContextManager::releaseCurrentContext() {
if (_currentContext != 0)
glFinish();
glFinish();
setCurrent(0);
}
......@@ -78,5 +79,16 @@ namespace tgt {
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;
}
}
}
}
......@@ -65,6 +65,13 @@ namespace tgt {
const ivec2& size = ivec2(GLCanvas::DEFAULT_WINDOW_WIDTH, GLCanvas::DEFAULT_WINDOW_HEIGHT),
const GLCanvas::Buffers buffers = GLCanvas::RGBADD,
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.
......@@ -109,7 +116,9 @@ namespace tgt {
std::map<std::string, GLCanvas*> _contexts; ///< Map of all OpenGL contexts
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_;
};
......
......@@ -18,6 +18,7 @@ namespace tgt {
// FIXME: rethink this concept of unique IDs
//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);
QtThreadedCanvas* toReturn = new QtThreadedCanvas(title, size, buffers, 0, shared);
_contexts.insert(std::make_pair(key, toReturn));
......
......@@ -43,12 +43,12 @@ namespace campvis {
VirtualMirrorGeometryGenerator::VirtualMirrorGeometryGenerator()
: AbstractProcessor()
, 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),
tgt::vec3(0.001f), tgt::ivec3(3), AbstractProcessor::VALID)
, p_size("mirrorSize", "Mirror Size", 4.0f, 0.1f, 1000.0f, 0.1f)
, 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")
{
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