mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
[Physics2] Avoid an exception when the object position is not finite (#7017)
This commit is contained in:
@@ -897,16 +897,21 @@ namespace gdjs {
|
||||
// Generate the body definition
|
||||
const bodyDef = new Box2D.b2BodyDef();
|
||||
|
||||
const x =
|
||||
(this.owner.getDrawableX() + this.owner.getWidth() / 2) *
|
||||
this._sharedData.worldInvScale;
|
||||
const y =
|
||||
(this.owner.getDrawableY() + this.owner.getHeight() / 2) *
|
||||
this._sharedData.worldInvScale;
|
||||
|
||||
// Set the initial body transformation from the GD object
|
||||
bodyDef.set_position(
|
||||
this.b2Vec2(
|
||||
(this.owner.getDrawableX() + this.owner.getWidth() / 2) *
|
||||
this._sharedData.worldInvScale,
|
||||
(this.owner.getDrawableY() + this.owner.getHeight() / 2) *
|
||||
this._sharedData.worldInvScale
|
||||
)
|
||||
this.b2Vec2(Number.isFinite(x) ? x : 0, Number.isFinite(y) ? y : 0)
|
||||
);
|
||||
bodyDef.set_angle(gdjs.toRad(this.owner.getAngle()));
|
||||
const angle = gdjs.toRad(this.owner.getAngle());
|
||||
if (Number.isFinite(angle)) {
|
||||
bodyDef.set_angle(angle);
|
||||
}
|
||||
|
||||
// Set body settings
|
||||
bodyDef.set_type(
|
||||
@@ -1014,13 +1019,21 @@ namespace gdjs {
|
||||
this._objectOldY !== this.owner.getY() ||
|
||||
this._objectOldAngle !== this.owner.getAngle()
|
||||
) {
|
||||
const pos = this.b2Vec2(
|
||||
const x =
|
||||
(this.owner.getDrawableX() + this.owner.getWidth() / 2) *
|
||||
this._sharedData.worldInvScale,
|
||||
this._sharedData.worldInvScale;
|
||||
const y =
|
||||
(this.owner.getDrawableY() + this.owner.getHeight() / 2) *
|
||||
this._sharedData.worldInvScale
|
||||
this._sharedData.worldInvScale;
|
||||
const pos = this.b2Vec2(
|
||||
Number.isFinite(x) ? x : body.GetPosition().x,
|
||||
Number.isFinite(y) ? y : body.GetPosition().y
|
||||
);
|
||||
const angle = gdjs.toRad(this.owner.getAngle());
|
||||
body.SetTransform(
|
||||
pos,
|
||||
Number.isFinite(angle) ? angle : body.GetAngle()
|
||||
);
|
||||
body.SetTransform(pos, gdjs.toRad(this.owner.getAngle()));
|
||||
body.SetAwake(true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user