2

私が理解しているように、Web 用の Box2D バージョンではメモリ リークが発生しており、ボディは削除されず、連絡先も削除されません。では、どうすればこの問題を解決できますか?

リークの仕方を説明している私の関連する質問を参照してください。Box2D バグ?

4

1 に答える 1

0

この投稿で、この問題にパッチを当てる方法が説明されている可能性があり ます http://devizgl.blogspot.com/2012/03/box2d21a.html

ファイル Box2dWeb-2.1.a.3.js にパッチを適用する必要があります

ステップ 1 メソッド Destroy() をクラス b2Body に追加します。

b2Body.prototype.Destroy = function () {

  this.m_userData = null;
  this.m_sweep = null;
  this.m_xf = null;
  this.m_linearVelocity = null;
  this.m_force = null;
  this.m_world = null;
  this.m_prev = null;
  this.m_next = null;
  this.m_fixtureList = null;
  this.m_controllerList = null;
  this.m_jointList = null;
  this.m_contactList = null;
}

ステップ 2 クラス b2World のメソッド DestroyBody の最後にコードを追加します。

...
--this.m_bodyCount;
  b.Destroy();
}

ステップ 3 このフィールドをクラス b2Contact に追加します。

...
this.m_swaped = false;

ステップ 4 クラス b2ContactFactory のメソッド Destroy にコードを追加します。

...
var reg = null;   

  if (contact.m_swaped) {
     reg = this.m_registers[type2][type1];
  }
  else {
     reg = this.m_registers[type1][type2];
  }

  contact.Reset();
...

ステップ 5 クラス b2ContactFactory のメソッド Create にコードを追加します。

...
if (reg.pool) {
     c = reg.pool;
     reg.pool = c.m_next;
     reg.poolCount--;
     // <---------------------
     if (c.m_swaped) {
        c.Reset(fixtureB, fixtureA);
     }
     else {
        c.Reset(fixtureA, fixtureB);
     }
     // <---------------------
     return c;
  }

  var createFcn = reg.createFcn;
  if (createFcn != null) {
     if (reg.primary) {
        c = createFcn(this.m_allocator);
        c.Reset(fixtureA, fixtureB);
        c.m_swaped = false;  // <------------------
        return c;
     }
else {
        c = createFcn(this.m_allocator);
        c.Reset(fixtureB, fixtureA);
        c.m_swaped = true;   // <------------------
        return c;
     }
  }
...
于 2014-03-24T23:22:20.837 に答える