@@ -10,6 +10,7 @@ import type { Nullable } from "../../types";
10
10
import type { Bone } from "../../Bones/bone" ;
11
11
import { Logger } from "../../Misc/logger" ;
12
12
import { TransformNode } from "../../Meshes/transformNode" ;
13
+ import type { Observer } from "core/Misc/observable" ;
13
14
14
15
/**
15
16
* Ragdoll bone properties
@@ -81,6 +82,7 @@ export class Ragdoll {
81
82
private _rootBoneIndex : number = - 1 ;
82
83
private _mass : number = 10 ;
83
84
private _restitution : number = 0 ;
85
+ private _beforeRenderObserver : Nullable < Observer < Scene > > = null ;
84
86
85
87
/**
86
88
* Pause synchronization between physics and bone position/orientation
@@ -362,7 +364,7 @@ export class Ragdoll {
362
364
}
363
365
364
366
this . _initJoints ( ) ;
365
- this . _scene . registerBeforeRender ( ( ) => {
367
+ this . _beforeRenderObserver = this . _scene . onBeforeRenderObservable . add ( ( ) => {
366
368
this . _syncBonesAndBoxes ( ) ;
367
369
} ) ;
368
370
this . _syncBonesToPhysics ( ) ;
@@ -392,5 +394,19 @@ export class Ragdoll {
392
394
for ( const aggregate of this . _aggregates ) {
393
395
aggregate . dispose ( ) ;
394
396
}
397
+ this . _aggregates . length = 0 ;
398
+ for ( const transform of this . _transforms ) {
399
+ transform . dispose ( ) ;
400
+ }
401
+ this . _transforms . length = 0 ;
402
+ for ( const constraint of this . _constraints ) {
403
+ constraint . dispose ( ) ;
404
+ }
405
+ this . _constraints . length = 0 ;
406
+
407
+ if ( this . _beforeRenderObserver ) {
408
+ this . _scene . onBeforeRenderObservable . remove ( this . _beforeRenderObserver ) ;
409
+ this . _beforeRenderObserver = null ;
410
+ }
395
411
}
396
412
}
0 commit comments