Skip to content

Commit

Permalink
[fix] box2d-wasm joint2d null check (#16337)
Browse files Browse the repository at this point in the history
  • Loading branch information
lealzhan authored Sep 26, 2023
1 parent d8f1be6 commit d437903
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

export class B2FixedJoint extends B2Joint implements IFixedJoint {
setFrequency (v: number): void {
(this._b2joint as B2.WeldJoint).SetFrequency(v);
if (this._b2joint) {
(this._b2joint as B2.WeldJoint).SetFrequency(v);
}
}
setDampingRatio (v: number): void {
(this._b2joint as B2.WeldJoint).SetDampingRatio(v);
if (this._b2joint) {
(this._b2joint as B2.WeldJoint).SetDampingRatio(v);
}
}

_createJointDef (): any {
Expand Down
9 changes: 6 additions & 3 deletions cocos/physics-2d/box2d-wasm/joints/spring-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types';

export class B2SpringJoint extends B2Joint implements ISpringJoint {
setFrequency (v: number): void {
(this._b2joint as B2.DistanceJoint).SetFrequency(v);
if (this._b2joint) {
(this._b2joint as B2.DistanceJoint).SetFrequency(v);
}
}

setDampingRatio (v: number): void {
//this.updateStiffnessAndDamping();
(this._b2joint as B2.DistanceJoint).SetDampingRatio(v);
if (this._b2joint) {
(this._b2joint as B2.DistanceJoint).SetDampingRatio(v);
}
}

setDistance (v: number): void {
Expand Down
8 changes: 6 additions & 2 deletions cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ import { toRadian } from '../../../core';

export class B2WheelJoint extends B2Joint implements IWheelJoint {
setFrequency (v: number): void {
(this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v);
if (this._b2joint) {
(this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v);
}
}
setDampingRatio (v: number): void {
(this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v);
if (this._b2joint) {
(this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v);
}
}

// motor
Expand Down

0 comments on commit d437903

Please sign in to comment.