-
Hi, I've came across a super weird issue. // Inside BatchSensor's body
SensorPtr gather(const UInt32 &idx, Mask active = true)const override{
return dr::gather<SensorPtr>(m_sensors_dr, idx, active);
} To make everything cleaner, I made a new "MultiSensor" interface deriving from Sensor, which contains this and other base virtual methods, so the BatchSensor now derives from it (the vector storing sensors was remade to use Sensor* instead of Base*). Using this custom gather function inside my integrator causes some super weird behavior when trying to call a member function, that isn't implemented in the BatchSensor itself. The function MyIntegrator::render(Sensor *sensor){
auto multiSensor = dynamic_cast<MultiSensor*>(sensor);
auto res = multiSensor->gather(idx)->sample_surface(); // Error not implemented BatchSensor::sample_surface()
} But rather than the function being called on the subsensors, that have the function implemented, I get a runtime error related to Why is this happening ? I'm so freaking confused. Edit, doesnt matter if I move the gather method into a member function of BatchSensor, I still get: std::tuple<DirectionSample3f, Float, Bool, Mask>
sample_surfaces(const Interaction3f &it, const Point2f &sample, const UInt32& idx, Mask active) const override{
SensorPtr sensor = dr::gather<SensorPtr>(m_sensors_dr, idx, active);
auto res = sensor->sample_surface(it, sample, active);
m_last_index = idx;
return res;
} Does the functions being called on subsensor having the same name and overriding the same method as the BatchSensor function have something to do with it ? Because calling the same way sample_ray() on subsensor from within the sample_ray() of the batch works totally fine !? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Just as I suspected... Making the BatchSensor overload the same method as is called inside the method itself works. std::tuple<DirectionSample3f, Float, Bool, Mask>
sample_surfaces(const Interaction3f &it, const Point2f &sample, const UInt32& idx, Mask active) const override{
SensorPtr sensor = dr::gather<SensorPtr>(m_sensors_dr, idx, active);
auto res = sensor->sample_surfaces(it, sample, idx, active);
m_last_index = idx;
return res;
} |
Beta Was this translation helpful? Give feedback.
-
Hi @xacond00 This is an artifact of how the just-in-time compiler works. For indirect calls, like a vectorized polymorphic method resolution in your case, the just-in-time compiler aggressively records the method of every single alive instance at that time. Why all of them? Well, at the time of recording/tracing, it cannot resolve the list of |
Beta Was this translation helpful? Give feedback.
Hi @xacond00
This is an artifact of how the just-in-time compiler works. For indirect calls, like a vectorized polymorphic method resolution in your case, the just-in-time compiler aggressively records the method of every single alive instance at that time. Why all of them? Well, at the time of recording/tracing, it cannot resolve the list of
SensorPtr
. So, it assumes the worst case scenario where every single object is in that list.