Skip to content

Commit e2854a9

Browse files
committed
Add contact overflow warnings.
1 parent ee84505 commit e2854a9

5 files changed

Lines changed: 184 additions & 33 deletions

File tree

newton/_src/solvers/kamino/_src/geometry/contacts.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ def _default_num_world_max_contacts() -> list[int]:
238238
Shape of ``(num_worlds,)``.
239239
"""
240240

241+
contact_overflow_warning_emitted: wp.array[wp.int32] | None = None
242+
"""Internal flag to track contact-buffer overflow warning messages."""
243+
241244
wid: wp.array[wp.int32] | None = None
242245
"""
243246
The world index of each active contact.
@@ -805,6 +808,7 @@ def finalize(
805808
model_active_contacts=wp.zeros(shape=1, dtype=wp.int32),
806809
world_max_contacts=to_warp_int32_array(world_max_contacts),
807810
world_active_contacts=wp.zeros(shape=len(world_max_contacts), dtype=wp.int32),
811+
contact_overflow_warning_emitted=wp.zeros(shape=1, dtype=wp.int32),
808812
wid=wp.full(value=-1, shape=(model_max_contacts,), dtype=wp.int32),
809813
cid=wp.full(value=-1, shape=(model_max_contacts,), dtype=wp.int32),
810814
gid_AB=wp.full(value=wp.vec2i(-1, -1), shape=(model_max_contacts,), dtype=wp.vec2i),
@@ -874,6 +878,7 @@ def _convert_contacts_newton_to_kamino(
874878
num_worlds: wp.int32,
875879
kamino_model_max_contacts: wp.array[wp.int32],
876880
kamino_world_max_contacts: wp.array[wp.int32],
881+
contact_overflow_warning_emitted: wp.array[wp.int32],
877882
newton_count: wp.array[wp.int32],
878883
newton_shape0: wp.array[wp.int32],
879884
newton_shape1: wp.array[wp.int32],
@@ -1026,11 +1031,21 @@ def _convert_contacts_newton_to_kamino(
10261031
wcid = wp.atomic_add(kamino_world_active, wid, 1)
10271032
if wcid >= world_max_contacts:
10281033
wp.atomic_sub(kamino_world_active, wid, 1)
1034+
if wp.atomic_exch(contact_overflow_warning_emitted, 0, 1) == 0:
1035+
wp.printf(
1036+
"Warning: Kamino per-world contact capacity exceeded while converting Newton contacts. "
1037+
"Increase Kamino contact capacity.\n"
1038+
)
10291039
return
10301040
mcid = wp.atomic_add(kamino_model_active, 0, 1)
10311041
if mcid >= model_max_contacts:
10321042
wp.atomic_sub(kamino_model_active, 0, 1)
10331043
wp.atomic_sub(kamino_world_active, wid, 1)
1044+
if wp.atomic_exch(contact_overflow_warning_emitted, 0, 1) == 0:
1045+
wp.printf(
1046+
"Warning: Kamino model contact capacity exceeded while converting Newton contacts. "
1047+
"Increase Kamino contact capacity.\n"
1048+
)
10341049
return
10351050

10361051
# Store the contact data in the Kamino format if the contact is valid
@@ -1383,6 +1398,7 @@ def convert_contacts_newton_to_kamino(
13831398
wp.int32(model.world_count),
13841399
contacts_out.model_max_contacts,
13851400
contacts_out.world_max_contacts,
1401+
contacts_out._data.contact_overflow_warning_emitted,
13861402
contacts_in.rigid_contact_count,
13871403
contacts_in.rigid_contact_shape0,
13881404
contacts_in.rigid_contact_shape1,

0 commit comments

Comments
 (0)