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

ViewportGadget : Range check gadget ids received from IECoreGL::Selector #5707

Merged
Merged
Changes from all commits
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
21 changes: 17 additions & 4 deletions src/GafferUI/ViewportGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#include "boost/bind/bind.hpp"
#include "boost/bind/placeholders.hpp"

#include "fmt/format.h"

#include <chrono>
#include <cmath>
#include <regex>
Expand Down Expand Up @@ -1116,10 +1118,21 @@ std::vector< Gadget* > ViewportGadget::gadgetsAtInternal( const Imath::Box2f &ra
std::vector< Gadget* > gadgets;
for( const HitRecord &it : selection )
{
// We can assume that renderInternal has populated m_renderItem, so we can just index into it
// using the index passed to loadName ( reversing the increment-by-one used to avoid the reserved
// name "0" )
gadgets.push_back( const_cast<Gadget*>( m_renderItems[ it.name - 1 ].gadget ) );
// We assume that `renderLayerInternal()` has populated `m_renderItem`, so we can just index into it
// using the index passed to `loadName()` (reversing the increment-by-one used to avoid the reserved
// name `0`). But we'd crash if we received out-of-range indices for any reason, so check.
const size_t index = it.name - 1;
if( index < m_renderItems.size() )
{
gadgets.push_back( const_cast<Gadget*>( m_renderItems[index].gadget ) );
}
else
{
IECore::msg(
IECore::Msg::Warning, "ViewportGadget::gadgetsAtInternal",
fmt::format( "Got out of bounds Gadget index {}", index )
);
}
}

if( !gadgets.size() )
Expand Down
Loading