Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DQT + Viewer crash when minimized when running on Debug #8693

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "../common/utilities/string/trim-newlines.h"
#include "../common/utilities/imgui/wrap.h"

#define FORCE_NON_NEGATIVE(input) input < 0 ? 0 : input
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the macro with inline, e.g.

template<typename T>
T non_negative(const T& input)
{
    return std::max(0, input)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, Done


namespace rs2
{
// Allocates a frameset from points and texture frames
Expand Down Expand Up @@ -1392,9 +1394,6 @@ namespace rs2
error_message = ex.what();
}




window.begin_viewport();

auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
Expand All @@ -1410,11 +1409,23 @@ namespace rs2

ImGui::Begin("Viewport", nullptr, { viewer_rect.w, viewer_rect.h }, 0.f, flags);

draw_viewport(viewer_rect, window, devices, error_message, texture_frame, p);
try
{
draw_viewport( viewer_rect, window, devices, error_message, texture_frame, p );

modal_notification_on = not_model->draw(window,
static_cast<int>(window.width()), static_cast<int>(window.height()),
error_message);
modal_notification_on = not_model->draw( window,
static_cast< int >( window.width() ),
static_cast< int >( window.height() ),
error_message );
}
catch( const error & e )
{
error_message = error_to_string( e );
}
catch( const std::exception & e )
{
error_message = e.what();
}

popup_if_error(window, error_message);

Expand Down Expand Up @@ -1930,8 +1941,8 @@ namespace rs2

auto bottom_y = win.framebuf_height() - viewer_rect.y - viewer_rect.h;

glViewport(static_cast<GLint>(viewer_rect.x), static_cast<GLint>(bottom_y),
static_cast<GLsizei>(viewer_rect.w), static_cast<GLsizei>(viewer_rect.h - top_bar_height));
glViewport(static_cast<GLint>(FORCE_NON_NEGATIVE(viewer_rect.x)), static_cast<GLint>(FORCE_NON_NEGATIVE(bottom_y)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above refactor may save the explicit casts and make it more readable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need the explicit cast , otherwise we get a warning

static_cast<GLsizei>(FORCE_NON_NEGATIVE(viewer_rect.w)), static_cast<GLsizei>(FORCE_NON_NEGATIVE(viewer_rect.h - top_bar_height)));

glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand All @@ -1940,7 +1951,7 @@ namespace rs2

glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluPerspective(45, viewer_rect.w / win.framebuf_height(), 0.001f, 100.0f);
gluPerspective(45, FORCE_NON_NEGATIVE(viewer_rect.w / win.framebuf_height()), 0.001f, 100.0f);
matrix4 perspective_mat;
glGetFloatv(GL_PROJECTION_MATRIX, perspective_mat);
glPopMatrix();
Expand Down
23 changes: 22 additions & 1 deletion tools/depth-quality/depth-quality-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,28 @@ namespace rs2
if (dpt)
_metrics_model.begin_process_frame(dpt);
}
catch (...){} // on device disconnect
catch( const error & e )
{
// Can occur on device disconnect
_viewer_model.not_model->output.add_log( RS2_LOG_SEVERITY_DEBUG,
__FILE__,
__LINE__,
error_to_string( e ) );
}
catch( const std::exception & e )
{
_viewer_model.not_model->output.add_log( RS2_LOG_SEVERITY_ERROR,
__FILE__,
__LINE__,
e.what() );
}
catch( ... )
{
_viewer_model.not_model->output.add_log( RS2_LOG_SEVERITY_ERROR,
__FILE__,
__LINE__,
"Unknown error occurred" );
}

}

Expand Down