diff --git a/model/Texture.cpp b/model/Texture.cpp index 06351a6d0..b984ab1cf 100644 --- a/model/Texture.cpp +++ b/model/Texture.cpp @@ -768,9 +768,9 @@ void opengl_texture::upload_from_thread(size_t width, size_t height, const uint8 { upload.fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } - else + if (upload.fence == nullptr) { - // no sync objects: the drawing context can only be sure of the image once the upload is done + // no sync objects, or no fence made: the drawing context can only be sure of the image once the upload is done glFinish(); } // the drawing context waits on the fence, which it can do only once the fence is on its way to the gpu diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index e5cfbccfb..866510f46 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -245,6 +245,9 @@ bool render_task::finish_upload() const { if (false == Global.python_uploadmain || nullptr == m_target || nullptr == m_target->shared_tex) return true; + // the old texture is deleted and the new name published under the lock the windows of python.displaywindows bind under, + // so none of them binds the old name once it is gone: a name bound before stays alive in its context while bound there + std::scoped_lock lock(m_target->mutex); if (m_uploadedbyworker) { if (false == m_target->shared_tex->commit_thread_upload()) @@ -254,7 +257,6 @@ bool render_task::finish_upload() const { upload(); } - std::scoped_lock lock(m_target->mutex); m_target->texture_id = m_target->shared_tex->get_id(); return true; } diff --git a/scripting/pythonscreenviewer.cpp b/scripting/pythonscreenviewer.cpp index 99e492963..5a3491af7 100644 --- a/scripting/pythonscreenviewer.cpp +++ b/scripting/pythonscreenviewer.cpp @@ -192,13 +192,11 @@ void python_screen_viewer::threadfunc() void python_screen_viewer::bind_shared_texture() const { - size_t texture; - { - std::scoped_lock guard(m_rt->mutex); - texture = m_rt->texture_id; - } // bound each frame: each image uploaded by a worker comes in a texture of its own, and a name deleted comes back for - // a later one, so a name seen before may be another texture already + // a later one, so a name seen before may be another texture already. bound under the lock the drawing thread deletes + // the old texture under, so the name read here is never one already gone + std::scoped_lock guard(m_rt->mutex); + size_t const texture = m_rt->texture_id; glBindTexture(GL_TEXTURE_2D, static_cast(texture != 0 ? texture : m_initialtexture)); }