korlibs / korge

KorGE Game Engine. Multiplatform Kotlin Game Engine
https://korge.org/
Other
2.54k stars 125 forks source link

KotlinNullPointerException when calling set of PolygonShape #275

Open kharf opened 4 years ago

kharf commented 4 years ago

example:

val vecs: Array<Vec2> = Array(8) { Vec2(1F, 1F) }
PolygonShape().set(vecs, vecs.size)

issue in org.jbox2d.collision.shapes.PolygonShape:

    // Perform welding and copy vertices into local buffer.
        val ps = if (vecPool != null)
            vecPool[Settings.maxPolygonVertices]
        else
            arrayOfNulls<Vec2>(Settings.maxPolygonVertices)
        var tempCount = 0
        for (i in 0 until n) {
            val v = verts[i]
            var unique = true
            for (j in 0 until tempCount) {
                if (MathUtils.distanceSquared(v, ps[j]!!) < 0.5f * Settings.linearSlop) {
                    unique = false
                    break
                }
            }

            if (unique) {
                ps[tempCount++]!!.set(v)
            }

ps will be an array of nulls. Unique is true in the first run, since tempCount is 0

soywiz commented 4 years ago

Did this work on original jbox2d?

kharf commented 4 years ago

Did this work on original jbox2d?

I can check

soywiz commented 4 years ago

@kharf did you check?

kharf commented 4 years ago

@soywiz sorry I checked it, forgot to reply. It worked when I tested it