Mercurial > hg > orthanc-stone
diff Framework/OpenGL/WebAssemblyOpenGLContext.cpp @ 956:a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
WebGL wrapper + added a LOT of logging messages right before throwing
ErrorCode_BadSequenceOfCalls exceptions + increased the http request timeouts
from 60 to 600 sec (big datasets in some recent customer use cases) + added
IsContext lost through the Viewport/Context layer (to make it reachable from
external API) + the same for the underlying device context (for debug)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 21 Aug 2019 16:16:30 +0200 |
parents | 1091b2adeb5a |
children | 769249e1f3b4 |
line wrap: on
line diff
--- a/Framework/OpenGL/WebAssemblyOpenGLContext.cpp Fri Aug 16 16:24:11 2019 +0200 +++ b/Framework/OpenGL/WebAssemblyOpenGLContext.cpp Wed Aug 21 16:16:30 2019 +0200 @@ -69,25 +69,48 @@ return reinterpret_cast<void*>(context_); } - bool IsContextLost() const - { + bool IsContextLost() + { + LOG(TRACE) << "IsContextLost() for context " << std::hex() << bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0); - bool ownFlag = isContextLost_; - if (ownFlag != apiFlag) - { - LOG(WARNING) << "Context loss, according to emscripten, is: " << apiFlag << " | while, according to internal state, is: " << ownFlag; - } - return ownFlag | apiFlag; - } - - void SetLostContext() + isContextLost_ = apiFlag; + return isContextLost_; + } + + void SetLostContext() { isContextLost_ = true; } ~PImpl() { - emscripten_webgl_destroy_context(context_); + try + { + EMSCRIPTEN_RESULT result = emscripten_webgl_destroy_context(context_); + if (result != EMSCRIPTEN_RESULT_SUCCESS) + { + LOG(ERROR) << "emscripten_webgl_destroy_context returned code " << result; + } + } + catch (const Orthanc::OrthancException& e) + { + if (e.HasDetails()) + { + LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What() << " Details: " << e.GetDetails(); + } + else + { + LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What(); + } + } + catch (const std::exception& e) + { + LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::~PImpl: " << e.what(); + } + catch (...) + { + LOG(ERROR) << "Unknown exception in WebAssemblyOpenGLContext::~PImpl"; + } } const std::string& GetCanvasIdentifier() const @@ -177,7 +200,50 @@ { } - bool WebAssemblyOpenGLContext::IsContextLost() const + //bool WebAssemblyOpenGLContext::TryRecreate() + //{ + // // LOG(ERROR) << "WebAssemblyOpenGLContext::TryRecreate() trying to recreate context"; + // try + // { + // std::string canvasId = GetCanvasIdentifier(); + // pimpl_.reset(new PImpl(canvasId)); + + // // no exception does not mean the context is fully + // // functional! Most probably, if we have >= than 16 + // // contexts, context wil remain lost for some time + // bool lost = IsContextLost(); + // if (lost) { + // // LOG(ERROR) << "WebAssemblyOpenGLContext::TryRecreate() context is still lost!"; + // return false; + // } else { + // return true; + // } + // } + // catch (const Orthanc::OrthancException& e) + // { + // if (e.HasDetails()) + // { + // LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::TryRecreate: " << e.What() << " Details: " << e.GetDetails(); + // } + // else + // { + // LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::TryRecreate: " << e.What(); + // } + // return false; + // } + // catch (const std::exception& e) + // { + // LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::TryRecreate: " << e.what(); + // return false; + // } + // catch (...) + // { + // LOG(ERROR) << "Unknown exception WebAssemblyOpenGLContext::in TryRecreate"; + // return false; + // } + //} + + bool WebAssemblyOpenGLContext::IsContextLost() { return pimpl_->IsContextLost(); }