SAM33 / jbox2d

Automatically exported from code.google.com/p/jbox2d
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Wrong reallocating in TOISolver #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
many contacts at the same time

Problem:
jbox2d 2.1.2
package org.jbox2d.dynamics.contacts
class TOISolver
method initialize(Contact[] contacts, int count, Body toiBody)

Sometimes i got an array index out of bounds exception at line 99: 
TOIConstraint constraint = m_constraints[i];

The problem is wrong reallocating:

if(m_count >= m_constraints.length){
    TOIConstraint[] old = m_constraints;
    m_constraints = new TOIConstraint[old.length*2];
    System.arraycopy(old, 0, m_constraints, 0, old.length);
    for(int i=old.length; i<m_constraints.length; i++){
        m_constraints[i] = new TOIConstraint();
    }
}

Exception occurs in the case m_count > old.length*2. This should work:

while(m_count >= m_constraints.length){
    TOIConstraint[] old = m_constraints;
    m_constraints = new TOIConstraint[old.length*2];
    System.arraycopy(old, 0, m_constraints, 0, old.length);
    for(int i=old.length; i<m_constraints.length; i++){
        m_constraints[i] = new TOIConstraint();
    }
}

Have a nice Day

Original issue reported on code.google.com by zel1...@gmail.com on 31 Jul 2011 at 7:51

GoogleCodeExporter commented 8 years ago
Thanks! Fixing this right now.

Original comment by toucansa...@gmail.com on 31 Jul 2011 at 8:27

GoogleCodeExporter commented 8 years ago
fixed in r502

Original comment by toucansa...@gmail.com on 31 Jul 2011 at 11:29