@@ -153,6 +153,13 @@ struct DRJIT_EXTRA_EXPORT TraversableBase : public nanobind::intrusive_base {
153153 static_assert ( \
154154 std::is_base_of<drjit::TraversableBase, \
155155 std::remove_pointer_t <decltype (this )>>::value); \
156+ /* \
157+ * Only traverse the objects for frozen functions, since \
158+ * accidentally traversing the scene in loops or vcalls can cause \
159+ * issues. \
160+ */ \
161+ if (!jit_flag (JitFlag::EnableObjectTraversal)) \
162+ return ; \
156163 if constexpr (!std::is_same_v<Base, drjit::TraversableBase>) \
157164 Base::traverse_1_cb_ro (payload, fn); \
158165 DRJIT_MAP (DR_TRAVERSE_MEMBER_RO, __VA_ARGS__) \
@@ -169,6 +176,16 @@ struct DRJIT_EXTRA_EXPORT TraversableBase : public nanobind::intrusive_base {
169176#define DR_TRAVERSE_CB_RW (Base, ...) \
170177 void traverse_1_cb_rw (void *payload, \
171178 drjit::detail::traverse_callback_rw fn) override { \
179+ static_assert ( \
180+ std::is_base_of<drjit::TraversableBase, \
181+ std::remove_pointer_t <decltype (this )>>::value); \
182+ /* \
183+ * Only traverse the objects for frozen functions, since \
184+ * accidentally traversing the scene in loops or vcalls can cause \
185+ * issues. \
186+ */ \
187+ if (!jit_flag (JitFlag::EnableObjectTraversal)) \
188+ return ; \
172189 if constexpr (!std::is_same_v<Base, drjit::TraversableBase>) \
173190 Base::traverse_1_cb_rw (payload, fn); \
174191 DRJIT_MAP (DR_TRAVERSE_MEMBER_RW, __VA_ARGS__) \
0 commit comments