diff --git a/Fltk/openglWindow.cpp b/Fltk/openglWindow.cpp index f42c5732067e53635f27f21b8abc52362e037b46..1684e4e72d1d4f8de09eba43d3b6b5384408a748 100644 --- a/Fltk/openglWindow.cpp +++ b/Fltk/openglWindow.cpp @@ -107,13 +107,14 @@ void openglWindow::drawBorder() void openglWindow::draw() { - static int locked = 0; - if(locked) - return; - else - locked = 1; + // some drawing routines can create data (STL triangulations, etc.): + // make sure that we don't fire draw() while we are already drawing + // (e.g. du to an impromptu Fl::check()) + static bool busy = false; + if(busy) return; + busy = true; - Msg::Debug("openglWindow->draw()"); + Msg::Debug("openglWindow::draw()"); _ctx->viewport[0] = 0; _ctx->viewport[1] = 0; @@ -197,7 +198,7 @@ void openglWindow::draw() drawBorder(); } - locked = 0; + busy = false; } openglWindow *openglWindow::_lastHandled = 0; @@ -512,7 +513,18 @@ bool openglWindow::processSelectionBuffer(int type, bool multipleSelection, int eles = (meshSelection && CTX::instance()->pickElements) ? 4 * m->getNumMeshElements() : 0; int size = 7 * (m->getNumVertices() + m->getNumEdges() + m->getNumFaces() + - m->getNumRegions() + eles) + 1000 ; + m->getNumRegions() + eles); + + if(!size) return false; // we won't get any hits: the model is empty! + + size += 1000; // security + + // some drawing routines can create data (STL triangulations, etc.): + // make sure that we don't fire redraw while we are already drawing + // (e.g. du to an impromptu Fl::check()) + static bool busy = false; + if(busy) return false; + busy = true; make_current(); GLuint *selectionBuffer = new GLuint[size]; @@ -532,6 +544,8 @@ bool openglWindow::processSelectionBuffer(int type, bool multipleSelection, GLint numhits = glRenderMode(GL_RENDER); _ctx->render_mode = drawContext::GMSH_RENDER; + busy = false; + if(!numhits){ // no hits delete [] selectionBuffer; return false; diff --git a/Graphics/drawGeom.cpp b/Graphics/drawGeom.cpp index 277604f6a6f9346a99325a707be8f868091e06a6..a6505b0082cf9bdb86796a47ae8ba4ee6d9df3d0 100644 --- a/Graphics/drawGeom.cpp +++ b/Graphics/drawGeom.cpp @@ -238,15 +238,8 @@ class drawGFace { { if (f->geomType() == GEntity::CompoundSurface) return; - if(CTX::instance()->geom.surfaceType > 0){ - // avoid reentrant calls - static bool busy = false; - if(!busy) { - busy = true; - f->fillVertexArray(f->geomType() == GEntity::ProjectionFace); - busy = false; - } - } + if(CTX::instance()->geom.surfaceType > 0) + f->fillVertexArray(f->geomType() == GEntity::ProjectionFace); Range<double> ubounds = f->parBounds(0); Range<double> vbounds = f->parBounds(1); @@ -318,26 +311,12 @@ class drawGFace { } void _drawPlaneGFace(GFace *f) { - if(CTX::instance()->geom.surfaceType > 0){ - // avoid reentrant calls - static bool busy = false; - if(!busy) { - busy = true; - f->fillVertexArray(); - busy = false; - } - } + if(CTX::instance()->geom.surfaceType > 0) + f->fillVertexArray(); if(!CTX::instance()->geom.surfaceType || !f->va_geom_triangles || - CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals){ - // avoid reentrant calls - static bool busy = false; - if(!busy) { - busy = true; - f->buildRepresentationCross(); - busy = false; - } - } + CTX::instance()->geom.surfacesNum || CTX::instance()->geom.normals) + f->buildRepresentationCross(); if(CTX::instance()->geom.surfaces) { if(CTX::instance()->geom.surfaceType > 0 && f->va_geom_triangles){ diff --git a/Graphics/drawMesh.cpp b/Graphics/drawMesh.cpp index 44f85260d6ff3e5e082ad688af68021ee919bc47..1c3404d16a8013dd7127997db565ad8aa7cbe259 100644 --- a/Graphics/drawMesh.cpp +++ b/Graphics/drawMesh.cpp @@ -1008,48 +1008,42 @@ void drawContext::drawMesh() glDisable((GLenum)(GL_CLIP_PLANE0 + i)); } - static bool busy = false; - if(!busy){ - busy = true; - - for(unsigned int i = 0; i < GModel::list.size(); i++){ - GModel *m = GModel::list[i]; - if(m->getVisibility()){ - int status = m->getMeshStatus(); - if(CTX::instance()->mesh.changed) { - Msg::Debug("Mesh has changed: reinitializing drawing data", - CTX::instance()->mesh.changed); - if(status >= 1 && CTX::instance()->mesh.changed & ENT_LINE) - std::for_each(m->firstEdge(), m->lastEdge(), initMeshGEdge()); - if(status >= 2 && CTX::instance()->mesh.changed & ENT_SURFACE){ - if(m->normals) delete m->normals; - m->normals = new smooth_normals(CTX::instance()->mesh.angleSmoothNormals); - if(CTX::instance()->mesh.smoothNormals) - std::for_each(m->firstFace(), m->lastFace(), initSmoothNormalsGFace()); - std::for_each(m->firstFace(), m->lastFace(), initMeshGFace()); - } - if(status >= 3 && CTX::instance()->mesh.changed & ENT_VOLUME) - std::for_each(m->firstRegion(), m->lastRegion(), initMeshGRegion()); + for(unsigned int i = 0; i < GModel::list.size(); i++){ + GModel *m = GModel::list[i]; + if(m->getVisibility()){ + int status = m->getMeshStatus(); + if(CTX::instance()->mesh.changed) { + Msg::Debug("Mesh has changed: reinitializing drawing data", + CTX::instance()->mesh.changed); + if(status >= 1 && CTX::instance()->mesh.changed & ENT_LINE) + std::for_each(m->firstEdge(), m->lastEdge(), initMeshGEdge()); + if(status >= 2 && CTX::instance()->mesh.changed & ENT_SURFACE){ + if(m->normals) delete m->normals; + m->normals = new smooth_normals(CTX::instance()->mesh.angleSmoothNormals); + if(CTX::instance()->mesh.smoothNormals) + std::for_each(m->firstFace(), m->lastFace(), initSmoothNormalsGFace()); + std::for_each(m->firstFace(), m->lastFace(), initMeshGFace()); } - if(isVisible(m)){ - if(status >= 0) - std::for_each(m->firstVertex(), m->lastVertex(), drawMeshGVertex(this)); - if(status >= 1) - std::for_each(m->firstEdge(), m->lastEdge(), drawMeshGEdge(this)); - if(status >= 2){ - beginFakeTransparency(); - std::for_each(m->firstFace(), m->lastFace(), drawMeshGFace(this)); - endFakeTransparency(); - } - if(status >= 3) - std::for_each(m->firstRegion(), m->lastRegion(), drawMeshGRegion(this)); + if(status >= 3 && CTX::instance()->mesh.changed & ENT_VOLUME) + std::for_each(m->firstRegion(), m->lastRegion(), initMeshGRegion()); + } + if(isVisible(m)){ + if(status >= 0) + std::for_each(m->firstVertex(), m->lastVertex(), drawMeshGVertex(this)); + if(status >= 1) + std::for_each(m->firstEdge(), m->lastEdge(), drawMeshGEdge(this)); + if(status >= 2){ + beginFakeTransparency(); + std::for_each(m->firstFace(), m->lastFace(), drawMeshGFace(this)); + endFakeTransparency(); } + if(status >= 3) + std::for_each(m->firstRegion(), m->lastRegion(), drawMeshGRegion(this)); } } - - CTX::instance()->mesh.changed = 0; - busy = false; } + + CTX::instance()->mesh.changed = 0; for(int i = 0; i < 6; i++) glDisable((GLenum)(GL_CLIP_PLANE0 + i)); diff --git a/Graphics/drawPost.cpp b/Graphics/drawPost.cpp index 50afbb9b2727471f0862a02274a9aab04c92729c..6bfd8fd24d7dc227fb5c2e4a66ad71cda276811b 100644 --- a/Graphics/drawPost.cpp +++ b/Graphics/drawPost.cpp @@ -446,12 +446,7 @@ void drawContext::drawPost() if(!CTX::instance()->post.draw) return; - static bool busy = false; - if(!busy){ - busy = true; - for(unsigned int i = 0; i < PView::list.size(); i++) - PView::list[i]->fillVertexArrays(); - std::for_each(PView::list.begin(), PView::list.end(), drawPView(this)); - busy = false; - } + for(unsigned int i = 0; i < PView::list.size(); i++) + PView::list[i]->fillVertexArrays(); + std::for_each(PView::list.begin(), PView::list.end(), drawPView(this)); }