From abc91ec761f41290f70e2a4267c063067c36070a Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Fri, 9 Oct 2020 15:02:43 +0200 Subject: [PATCH] * fixing some undefined behavior * clearing textures before drawing (this could be optimized by clearing only a portion of the remaining image, but this is pretty close to optimum in GL) --- Application/CMakeLists.txt | 2 +- .../commons/common/cpputils/debug/Debug.cpp | 4 ++-- Application/src/commons/common/gui/GLImpl.cpp | 20 +++++++++++++++++-- .../src/tracker/tracking/DatasetQuality.cpp | 3 ++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Application/CMakeLists.txt b/Application/CMakeLists.txt index a1bc6d1..2e411a7 100644 --- a/Application/CMakeLists.txt +++ b/Application/CMakeLists.txt @@ -802,7 +802,7 @@ if(${TREX_BUILD_OPENCV}) -DBUILD_DOCS:BOOL=FALSE -DBUILD_EXAMPLES:BOOL=FALSE -DBUILD_TESTS:BOOL=FALSE - -DCMAKE_BUILD_TYPE=Release + -DCMAKE_BUILD_TYPE=$<$<CONFIG:Debug>:Release>$<$<CONFIG:Release>:Debug> -DBUILD_SHARED_LIBS:BOOL=FALSE -DBUILD_NEW_PYTHON_SUPPORT:BOOL=OFF -DBUILD_WITH_DEBUG_INFO=OFF diff --git a/Application/src/commons/common/cpputils/debug/Debug.cpp b/Application/src/commons/common/cpputils/debug/Debug.cpp index 5db6822..6c7c22f 100644 --- a/Application/src/commons/common/cpputils/debug/Debug.cpp +++ b/Application/src/commons/common/cpputils/debug/Debug.cpp @@ -516,7 +516,7 @@ insert_start(tree, ¤t_node, e); } case '<': case '>': case ':': - if (current == '<' || (current == ':' && i < msg->buf.length() && msg->buf[i + 1] != ':' && (size_t)word_start != i)) { + if (current == '<' || (current == ':' && i+1 < msg->buf.length() && msg->buf[i + 1] != ':' && (size_t)word_start != i)) { TreeNode<DEBUG::PARSE_OBJECTS> *node; long str_start = -1; long off = 0; @@ -564,7 +564,7 @@ insert_start(tree, ¤t_node, e); } if (current == ':') { // match ':' pairs - if ((i < msg->buf.length() && msg->buf[i + 1] == ':') + if ((i+1 < msg->buf.length() && msg->buf[i + 1] == ':') || (i > 0 && msg->buf[i - 1] == ':')) { INSERT_SINGLE(PARSE_OBJECTS::CLASSSEPERATOR, i); diff --git a/Application/src/commons/common/gui/GLImpl.cpp b/Application/src/commons/common/gui/GLImpl.cpp index 5770433..d8f616b 100644 --- a/Application/src/commons/common/gui/GLImpl.cpp +++ b/Application/src/commons/common/gui/GLImpl.cpp @@ -332,6 +332,8 @@ void GLImpl::check_thread_id(int line, const char* file) const { #endif } +static std::vector<uchar> empty; + TexturePtr GLImpl::texture(const Image * ptr) { GLIMPL_CHECK_THREAD_ID(); @@ -372,7 +374,12 @@ TexturePtr GLImpl::texture(const Image * ptr) { #endif auto width = next_pow2(ptr->cols), height = next_pow2(ptr->rows); - glTexImage2D(GL_TEXTURE_2D, 0, output_type, width, height, 0, input_type, GL_UNSIGNED_BYTE, NULL); + auto capacity = size_t(ptr->dims) * size_t(width) * size_t(height); + if (empty.size() < capacity) + empty.resize(capacity, 0); + + glTexImage2D(GL_TEXTURE_2D, 0, output_type, width, height, 0, input_type, GL_UNSIGNED_BYTE, empty.data()); + glTexSubImage2D(GL_TEXTURE_2D,0,0,0, ptr->cols, ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); glBindTexture(GL_TEXTURE_2D, 0); @@ -451,7 +458,16 @@ void GLImpl::update_texture(PlatformTexture& id_, const Image *ptr) { input_type = GL_RG; } #endif - + + auto capacity = size_t(ptr->dims) * size_t(id_.width) * size_t(id_.height); + if (empty.size() < capacity) + empty.resize(capacity, 0); + + if (ptr->cols != id_.width || ptr->rows != id_.height) { + glTexSubImage2D(GL_TEXTURE_2D, 0, ptr->cols, 0, id_.width - ptr->cols, id_.height, input_type, GL_UNSIGNED_BYTE, empty.data()); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, ptr->rows, ptr->cols, id_.height - ptr->rows, input_type, GL_UNSIGNED_BYTE, empty.data()); + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, id_.width, id_.height, input_type, GL_UNSIGNED_BYTE, empty.data()); + } glTexSubImage2D(GL_TEXTURE_2D,0,0,0, ptr->cols, ptr->rows, input_type, GL_UNSIGNED_BYTE, ptr->data()); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ptr->cols, ptr->rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptr->data()); glBindTexture(GL_TEXTURE_2D, 0); diff --git a/Application/src/tracker/tracking/DatasetQuality.cpp b/Application/src/tracker/tracking/DatasetQuality.cpp index 6d7de49..310d48f 100644 --- a/Application/src/tracker/tracking/DatasetQuality.cpp +++ b/Application/src/tracker/tracking/DatasetQuality.cpp @@ -275,7 +275,8 @@ DatasetQuality::Single DatasetQuality::evaluate_single(idx_t id, Individual* fis long_t number_frames = 0; bool debug = false; - if(FAST_SETTINGS(manually_approved).find(_consec.start) != FAST_SETTINGS(manually_approved).end()) + auto manually_approved = FAST_SETTINGS(manually_approved); + if(manually_approved.find(_consec.start) != manually_approved.end()) debug = true; FrameRange consec(Rangel(-1, -1)); -- GitLab