Skip to content

Commit

Permalink
Merge pull request #5707 from johnhaddon/viewportGadgetSanityChecks
Browse files Browse the repository at this point in the history
ViewportGadget : Range check gadget ids received from `IECoreGL::Selector`
  • Loading branch information
murraystevenson authored Mar 5, 2024
2 parents 20d8c16 + 189c5c1 commit b312302
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit b312302

Please sign in to comment.