@@ -118,7 +118,9 @@ protected long getSceneHandle() {
118118 @ Override
119119 public void init (@ Nullable final Vector3dc gravity , final double universalDrag ) {
120120 try {
121+ Sable .LOGGER .info ("[SableDebug] Initializing Rapier physics pipeline with gravity=({}, {}, {}), drag={}" , gravity .x (), gravity .y (), gravity .z (), universalDrag );
121122 this .scene = new RapierPhysicsScene (Rapier3D .initialize (gravity .x (), gravity .y (), gravity .z (), universalDrag ));
123+ Sable .LOGGER .info ("[SableDebug] Rapier physics pipeline initialized successfully, scene handle={}" , this .scene .handle ());
122124 } catch (final UnsatisfiedLinkError e ) {
123125 Sable .LOGGER .error ("Sable has failed to link with the natives for its Rapier pipeline. Please report with system details to " + Sable .ISSUE_TRACKER_URL , e );
124126 final CrashReport crashReport = CrashReport .forThrowable (e .getCause (), "Sable linking with Rapier natives" );
@@ -145,7 +147,13 @@ public void dispose() {
145147 @ Override
146148 public void prePhysicsTicks () {
147149 final double timeStep = 1.0 / 20.0 ;
148- Rapier3D .tick (this .scene .handle (), timeStep );
150+ try {
151+ Sable .LOGGER .debug ("[SableDebug] prePhysicsTicks: calling tick(handle={}, timeStep={})" , this .scene .handle (), timeStep );
152+ Rapier3D .tick (this .scene .handle (), timeStep );
153+ } catch (final Exception e ) {
154+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in prePhysicsTicks tick() call" , e );
155+ throw e ;
156+ }
149157 }
150158
151159 /**
@@ -156,14 +164,26 @@ public void prePhysicsTicks() {
156164 @ Override
157165 public void physicsTick (final double timeStep ) {
158166 this .updateContraptionPoses ();
159- Rapier3D .step (this .scene .handle (), timeStep );
167+ try {
168+ Sable .LOGGER .debug ("[SableDebug] physicsTick: calling step(handle={}, timeStep={})" , this .scene .handle (), timeStep );
169+ Rapier3D .step (this .scene .handle (), timeStep );
170+ } catch (final Exception e ) {
171+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in physicsTick step() call" , e );
172+ throw e ;
173+ }
160174
161175 for (final PhysicsPipelineBody queuedWakeUp : this .queuedWakeUps ) {
162176 if (queuedWakeUp .isRemoved ()) {
163177 continue ;
164178 }
165179
166- Rapier3D .wakeUpObject (this .scene .handle (), queuedWakeUp .getRuntimeId ());
180+ final int wakeId = Rapier3D .getID (queuedWakeUp );
181+ Sable .LOGGER .debug ("[SableDebug] physicsTick: waking up body id={}" , wakeId );
182+ try {
183+ Rapier3D .wakeUpObject (this .scene .handle (), wakeId );
184+ } catch (final Exception e ) {
185+ Sable .LOGGER .error ("[SableDebug] EXCEPTION waking up body id={}" , wakeId , e );
186+ }
167187 }
168188
169189 this .queuedWakeUps .clear ();
@@ -195,27 +215,42 @@ public void add(final ServerSubLevel subLevel, final Pose3dc pose) {
195215 final Quaterniondc rot = pose .orientation ();
196216
197217 final int id = Rapier3D .getID (subLevel );
198- Rapier3D .createSubLevel (this .scene .handle (), id , new double []{pos .x (), pos .y (), pos .z (), rot .x (), rot .y (), rot .z (), rot .w ()});
218+ Sable .LOGGER .info ("[SableDebug] add(SubLevel): id={}, pos=({}, {}, {}), rot=({}, {}, {}, {})" , id , pos .x (), pos .y (), pos .z (), rot .x (), rot .y (), rot .z (), rot .w ());
219+ try {
220+ Rapier3D .createSubLevel (this .scene .handle (), id , new double []{pos .x (), pos .y (), pos .z (), rot .x (), rot .y (), rot .z (), rot .w ()});
221+ } catch (final Exception e ) {
222+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in add(SubLevel) createSubLevel, id={}" , id , e );
223+ throw e ;
224+ }
199225
200226 subLevel .updateMergedMassData (1.0f );
201227 final Vector3dc centerOfMass = subLevel .getMassTracker ().getCenterOfMass ();
202228
203229 if (centerOfMass != null ) {
204230 subLevel .logicalPose ().rotationPoint ().set (centerOfMass );
205-
231+ Sable . LOGGER . info ( "[SableDebug] add(SubLevel): id={}, centerOfMass=({}, {}, {})" , id , centerOfMass . x (), centerOfMass . y (), centerOfMass . z ());
206232 this .onStatsChanged (subLevel );
207233 }
208234
209235 this .activeSubLevels .put (Rapier3D .getID (subLevel ), subLevel );
236+ Sable .LOGGER .info ("[SableDebug] add(SubLevel): id={} added successfully, activeSubLevels.size={}" , id , this .activeSubLevels .size ());
210237 }
211238
212239 /**
213240 * Removes a {@link SubLevel} from the physics pipeline.
214241 */
215242 @ Override
216243 public void remove (final ServerSubLevel subLevel ) {
217- Rapier3D .removeSubLevel (this .scene .handle (), Rapier3D .getID (subLevel ));
218- this .activeSubLevels .remove (Rapier3D .getID (subLevel ));
244+ final int id = Rapier3D .getID (subLevel );
245+ Sable .LOGGER .info ("[SableDebug] remove(SubLevel): id={}" , id );
246+ try {
247+ Rapier3D .removeSubLevel (this .scene .handle (), id );
248+ } catch (final Exception e ) {
249+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in remove(SubLevel), id={}" , id , e );
250+ throw e ;
251+ }
252+ this .activeSubLevels .remove (id );
253+ Sable .LOGGER .info ("[SableDebug] remove(SubLevel): id={} removed, activeSubLevels.size={}" , id , this .activeSubLevels .size ());
219254 }
220255
221256 /**
@@ -301,11 +336,19 @@ public void remove(final KinematicContraption contraption) {
301336 @ Override
302337 public Pose3d readPose (final ServerSubLevel subLevel , final Pose3d dest ) {
303338 this .assertBodyValid (subLevel );
304- Rapier3D .getPose (this .scene .handle (), Rapier3D .getID (subLevel ), this .poseCache );
339+ final int id = Rapier3D .getID (subLevel );
340+ Sable .LOGGER .debug ("[SableDebug] readPose: id={}" , id );
341+ try {
342+ Rapier3D .getPose (this .scene .handle (), id , this .poseCache );
343+ } catch (final Exception e ) {
344+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in readPose getPose(), id={}" , id , e );
345+ throw e ;
346+ }
305347
306348 dest .position ().set (this .poseCache [0 ], this .poseCache [1 ], this .poseCache [2 ]);
307349 dest .orientation ().set (this .poseCache [3 ], this .poseCache [4 ], this .poseCache [5 ], this .poseCache [6 ]);
308350
351+ Sable .LOGGER .debug ("[SableDebug] readPose: id={}, pos=({}, {}, {}), rot=({}, {}, {}, {})" , id , this .poseCache [0 ], this .poseCache [1 ], this .poseCache [2 ], this .poseCache [3 ], this .poseCache [4 ], this .poseCache [5 ], this .poseCache [6 ]);
309352 return dest ;
310353 }
311354
@@ -331,6 +374,7 @@ public BoxHandle addBox(final BoxPhysicsObject box) {
331374 @ Override
332375 public void handleChunkSectionAddition (final LevelChunkSection section , final int x , final int y , final int z , final boolean uploadDataIfGlobal ) {
333376 this .accelerator .clearCache ();
377+ Sable .LOGGER .debug ("[SableDebug] handleChunkSectionAddition: section=({}, {}, {}), uploadDataIfGlobal={}, hasOnlyAir={}" , x , y , z , uploadDataIfGlobal , section .hasOnlyAir ());
334378
335379 // this means the x coordinate is the fastest changing, then z, then y
336380 final int [] array = new int [LevelChunkSection .SECTION_SIZE ];
@@ -362,15 +406,26 @@ public void handleChunkSectionAddition(final LevelChunkSection section, final in
362406 int id = -1 ;
363407
364408 if (plot != null && uploadDataIfGlobal ) id = Rapier3D .getID (((ServerSubLevel ) plot .getSubLevel ()));
365- Rapier3D .addChunk (this .scene .handle (), x , y , z , array , global , id );
409+ try {
410+ Rapier3D .addChunk (this .scene .handle (), x , y , z , array , global , id );
411+ } catch (final Exception e ) {
412+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in handleChunkSectionAddition addChunk({}, {}, {}), global={}, id={}" , x , y , z , global , id , e );
413+ throw e ;
414+ }
366415 }
367416
368417 /**
369418 * Handles the removal of a chunk section from the physics context
370419 */
371420 @ Override
372421 public void handleChunkSectionRemoval (final int x , final int y , final int z ) {
373- Rapier3D .removeChunk (this .scene .handle (), x , y , z , !SubLevelContainer .getContainer (this .level ).inBounds (x , z ));
422+ Sable .LOGGER .debug ("[SableDebug] handleChunkSectionRemoval: ({}, {}, {})" , x , y , z );
423+ try {
424+ Rapier3D .removeChunk (this .scene .handle (), x , y , z , !SubLevelContainer .getContainer (this .level ).inBounds (x , z ));
425+ } catch (final Exception e ) {
426+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in handleChunkSectionRemoval removeChunk({}, {}, {})" , x , y , z , e );
427+ throw e ;
428+ }
374429 }
375430
376431 /**
@@ -387,6 +442,8 @@ public void handleBlockChange(final SectionPos sectionPos, final LevelChunkSecti
387442 y = (sectionPos .y () << 4 ) + y ;
388443 z = (sectionPos .z () << 4 ) + z ;
389444
445+ Sable .LOGGER .debug ("[SableDebug] handleBlockChange: pos=({}, {}, {}), oldState={}, newState={}" , x , y , z , oldState , newState );
446+
390447 final BlockPos globalBlockPos = new BlockPos (x , y , z );
391448
392449 for (final Direction dir : Direction .values ()) {
@@ -395,15 +452,25 @@ public void handleBlockChange(final SectionPos sectionPos, final LevelChunkSecti
395452 final RapierVoxelColliderData colliderData = this .colliderBakery .getPhysicsDataForBlock (this .level .getBlockState (pos ));
396453
397454 final int colliderValue = colliderData == null ? 0 : colliderData .handle () + 1 ;
398- Rapier3D .changeBlock (this .scene .handle (), pos .getX (), pos .getY (), pos .getZ (), packBlockState (state , colliderValue ));
455+ try {
456+ Rapier3D .changeBlock (this .scene .handle (), pos .getX (), pos .getY (), pos .getZ (), packBlockState (state , colliderValue ));
457+ } catch (final Exception e ) {
458+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in handleBlockChange changeBlock neighbor ({}, {}, {}), colliderValue={}" , pos .getX (), pos .getY (), pos .getZ (), colliderValue , e );
459+ throw e ;
460+ }
399461 }
400462
401463 // do it for the block without offset
402464 final VoxelNeighborhoodState state = VoxelNeighborhoodState .getState (this .accelerator , globalBlockPos , null );
403465 final RapierVoxelColliderData colliderData = this .colliderBakery .getPhysicsDataForBlock (newState );
404466
405467 final int colliderValue = colliderData == null ? 0 : colliderData .handle () + 1 ;
406- Rapier3D .changeBlock (this .scene .handle (), x , y , z , packBlockState (state , colliderValue ));
468+ try {
469+ Rapier3D .changeBlock (this .scene .handle (), x , y , z , packBlockState (state , colliderValue ));
470+ } catch (final Exception e ) {
471+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in handleBlockChange changeBlock self ({}, {}, {}), colliderValue={}" , x , y , z , colliderValue , e );
472+ throw e ;
473+ }
407474 }
408475
409476 @ Override
@@ -415,11 +482,23 @@ public void onStatsChanged(@NotNull final ServerSubLevel subLevel) {
415482
416483 final Vector3dc centerOfMass = subLevel .getMassTracker ().getCenterOfMass ();
417484 if (centerOfMass != null ) {
418- Rapier3D .setCenterOfMass (this .scene .handle (), id , centerOfMass .x (), centerOfMass .y (), centerOfMass .z ());
419- Rapier3D .setMassPropertiesFrom (this .scene .handle (), id , subLevel .getMassTracker ());
485+ Sable .LOGGER .debug ("[SableDebug] onStatsChanged: id={}, centerOfMass=({}, {}, {}), mass={}" , id , centerOfMass .x (), centerOfMass .y (), centerOfMass .z (), subLevel .getMassTracker ().getMass ());
486+ try {
487+ Rapier3D .setCenterOfMass (this .scene .handle (), id , centerOfMass .x (), centerOfMass .y (), centerOfMass .z ());
488+ Rapier3D .setMassPropertiesFrom (this .scene .handle (), id , subLevel .getMassTracker ());
489+ } catch (final Exception e ) {
490+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in onStatsChanged setCenterOfMass/setMassProperties, id={}" , id , e );
491+ throw e ;
492+ }
420493 }
421494
422- Rapier3D .setLocalBounds (this .scene .handle (), id , plotBounds .minX (), plotBounds .minY (), plotBounds .minZ (), plotBounds .maxX (), plotBounds .maxY (), plotBounds .maxZ ());
495+ Sable .LOGGER .debug ("[SableDebug] onStatsChanged: id={}, bounds=({},{},{} -> {},{},{})" , id , plotBounds .minX (), plotBounds .minY (), plotBounds .minZ (), plotBounds .maxX (), plotBounds .maxY (), plotBounds .maxZ ());
496+ try {
497+ Rapier3D .setLocalBounds (this .scene .handle (), id , plotBounds .minX (), plotBounds .minY (), plotBounds .minZ (), plotBounds .maxX (), plotBounds .maxY (), plotBounds .maxZ ());
498+ } catch (final Exception e ) {
499+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in onStatsChanged setLocalBounds, id={}" , id , e );
500+ throw e ;
501+ }
423502 }
424503
425504 /**
@@ -433,7 +512,14 @@ public void onStatsChanged(@NotNull final ServerSubLevel subLevel) {
433512 public void teleport (final PhysicsPipelineBody body , final Vector3dc position , final Quaterniondc orientation ) {
434513 this .assertBodyValid (body );
435514
436- Rapier3D .teleportObject (this .scene .handle (), Rapier3D .getID (body ), position .x (), position .y (), position .z (), orientation .x (), orientation .y (), orientation .z (), orientation .w ());
515+ final int id = Rapier3D .getID (body );
516+ Sable .LOGGER .debug ("[SableDebug] teleport: id={}, pos=({}, {}, {}), rot=({}, {}, {}, {})" , id , position .x (), position .y (), position .z (), orientation .x (), orientation .y (), orientation .z (), orientation .w ());
517+ try {
518+ Rapier3D .teleportObject (this .scene .handle (), id , position .x (), position .y (), position .z (), orientation .x (), orientation .y (), orientation .z (), orientation .w ());
519+ } catch (final Exception e ) {
520+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in teleport, id={}" , id , e );
521+ throw e ;
522+ }
437523 if (body instanceof final ServerSubLevel subLevel ) {
438524 subLevel .logicalPose ().position ().set (position );
439525 subLevel .logicalPose ().orientation ().set (orientation );
@@ -451,8 +537,15 @@ public void teleport(final PhysicsPipelineBody body, final Vector3dc position, f
451537 public void applyImpulse (final PhysicsPipelineBody body , final Vector3dc position , final Vector3dc force ) {
452538 this .assertBodyValid (body );
453539
540+ final int id = Rapier3D .getID (body );
454541 final Vector3dc centerOfMass = body .getMassTracker ().getCenterOfMass ();
455- Rapier3D .applyForce (this .scene .handle (), Rapier3D .getID (body ), position .x () - centerOfMass .x (), position .y () - centerOfMass .y (), position .z () - centerOfMass .z (), force .x (), force .y (), force .z (), true );
542+ Sable .LOGGER .debug ("[SableDebug] applyImpulse: id={}, relPos=({}, {}, {}), force=({}, {}, {})" , id , position .x () - centerOfMass .x (), position .y () - centerOfMass .y (), position .z () - centerOfMass .z (), force .x (), force .y (), force .z ());
543+ try {
544+ Rapier3D .applyForce (this .scene .handle (), id , position .x () - centerOfMass .x (), position .y () - centerOfMass .y (), position .z () - centerOfMass .z (), force .x (), force .y (), force .z (), true );
545+ } catch (final Exception e ) {
546+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in applyImpulse, id={}" , id , e );
547+ throw e ;
548+ }
456549 }
457550
458551 /**
@@ -464,7 +557,14 @@ public void applyImpulse(final PhysicsPipelineBody body, final Vector3dc positio
464557 @ Override
465558 public void applyLinearAndAngularImpulse (final PhysicsPipelineBody body , final Vector3dc force , final Vector3dc torque , final boolean wakeUp ) {
466559 this .assertBodyValid (body );
467- Rapier3D .applyForceAndTorque (this .scene .handle (), Rapier3D .getID (body ), force .x (), force .y (), force .z (), torque .x (), torque .y (), torque .z (), wakeUp );
560+ final int id = Rapier3D .getID (body );
561+ Sable .LOGGER .debug ("[SableDebug] applyLinearAndAngularImpulse: id={}, force=({}, {}, {}), torque=({}, {}, {}), wakeUp={}" , id , force .x (), force .y (), force .z (), torque .x (), torque .y (), torque .z (), wakeUp );
562+ try {
563+ Rapier3D .applyForceAndTorque (this .scene .handle (), id , force .x (), force .y (), force .z (), torque .x (), torque .y (), torque .z (), wakeUp );
564+ } catch (final Exception e ) {
565+ Sable .LOGGER .error ("[SableDebug] EXCEPTION in applyLinearAndAngularImpulse, id={}" , id , e );
566+ throw e ;
567+ }
468568 }
469569
470570 /**
0 commit comments