Skip to content

Commit 69b999a

Browse files
authored
Merge pull request #183 from alexandernanberg/fix-free
fix: don't panic if calling .free() multiple times
2 parents fc7ade6 + 6dfbf90 commit 69b999a

14 files changed

+64
-20
lines changed

src.ts/dynamics/ccd_solver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export class CCDSolver {
1313
* Release the WASM memory occupied by this narrow-phase.
1414
*/
1515
public free() {
16-
this.raw.free();
16+
if (!!this.raw) {
17+
this.raw.free();
18+
}
1719
this.raw = undefined;
1820
}
1921

src.ts/dynamics/impulse_joint_set.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ export class ImpulseJointSet {
3131
* Release the WASM memory occupied by this joint set.
3232
*/
3333
public free() {
34-
this.raw.free();
34+
if (!!this.raw) {
35+
this.raw.free();
36+
}
3537
this.raw = undefined;
36-
this.map.clear();
38+
39+
if (!!this.map) {
40+
this.map.clear();
41+
}
3742
this.map = undefined;
3843
}
3944

src.ts/dynamics/integration_parameters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export class IntegrationParameters {
1111
* Free the WASM memory used by these integration parameters.
1212
*/
1313
public free() {
14-
this.raw.free();
14+
if (!!this.raw) {
15+
this.raw.free();
16+
}
1517
this.raw = undefined;
1618
}
1719

src.ts/dynamics/island_manager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export class IslandManager {
1414
* Release the WASM memory occupied by this narrow-phase.
1515
*/
1616
public free() {
17-
this.raw.free();
17+
if (!!this.raw) {
18+
this.raw.free();
19+
}
1820
this.raw = undefined;
1921
}
2022

src.ts/dynamics/multibody_joint_set.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ export class MultibodyJointSet {
3030
* Release the WASM memory occupied by this joint set.
3131
*/
3232
public free() {
33-
this.raw.free();
33+
if (!!this.raw) {
34+
this.raw.free();
35+
}
3436
this.raw = undefined;
35-
this.map.clear();
37+
38+
if (!!this.map) {
39+
this.map.clear();
40+
}
3641
this.map = undefined;
3742
}
3843

src.ts/dynamics/rigid_body_set.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ export class RigidBodySet {
2121
* Release the WASM memory occupied by this rigid-body set.
2222
*/
2323
public free() {
24-
this.raw.free();
24+
if (!!this.raw) {
25+
this.raw.free();
26+
}
2527
this.raw = undefined;
26-
this.map.clear();
28+
29+
if (!!this.map) {
30+
this.map.clear();
31+
}
2732
this.map = undefined;
2833
}
2934

src.ts/geometry/broad_phase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export class BroadPhase {
1313
* Release the WASM memory occupied by this broad-phase.
1414
*/
1515
public free() {
16-
this.raw.free();
16+
if (!!this.raw) {
17+
this.raw.free();
18+
}
1719
this.raw = undefined;
1820
}
1921

src.ts/geometry/collider_set.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ export class ColliderSet {
1919
* Release the WASM memory occupied by this collider set.
2020
*/
2121
public free() {
22-
this.raw.free();
22+
if (!!this.raw) {
23+
this.raw.free();
24+
}
2325
this.raw = undefined;
24-
this.map.clear();
26+
27+
if (!!this.map) {
28+
this.map.clear();
29+
}
2530
this.map = undefined;
2631
}
2732

src.ts/geometry/narrow_phase.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export class NarrowPhase {
1616
* Release the WASM memory occupied by this narrow-phase.
1717
*/
1818
public free() {
19-
this.raw.free();
19+
if (!!this.raw) {
20+
this.raw.free();
21+
}
2022
this.raw = undefined;
2123
}
2224

@@ -101,7 +103,9 @@ export class TempContactManifold {
101103
raw: RawContactManifold;
102104

103105
public free() {
104-
this.raw.free();
106+
if (!!this.raw) {
107+
this.raw.free();
108+
}
105109
this.raw = undefined;
106110
}
107111

src.ts/pipeline/debug_render_pipeline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export class DebugRenderPipeline {
4848
* Release the WASM memory occupied by this serialization pipeline.
4949
*/
5050
free() {
51-
this.raw.free();
51+
if (!!this.raw) {
52+
this.raw.free();
53+
}
5254
this.raw = undefined;
5355
this.vertices = undefined;
5456
this.colors = undefined;

0 commit comments

Comments
 (0)