Skip to content

Fix NPE in Geometry's morph state (#2919) - #2920

Open
DieterDePaepe wants to merge 1 commit into
jMonkeyEngine:masterfrom
DieterDePaepe:fix-geometry-morphstate-npe
Open

Fix NPE in Geometry's morph state (#2919)#2920
DieterDePaepe wants to merge 1 commit into
jMonkeyEngine:masterfrom
DieterDePaepe:fix-geometry-morphstate-npe

Conversation

@DieterDePaepe

Copy link
Copy Markdown
Contributor

Geometry allocates its morphState array lazily. setMorphState(float[]) and getMorphState() both create it on demand, but the name-based overloads setMorphState(String, float) and getMorphState(String) indexed the field directly, so calling either one first threw NullPointerException:

java.lang.NullPointerException: Cannot store to float array because
"this.morphState" is null

Nothing else populates the array. MorphControl only reads it, and the control itself is attached by GltfLoader only when the asset carries an animation channel targeting "weights". An application driving morph targets from its own code -- expression blending, a slider, anything procedural -- therefore has an unallocated array precisely when it reaches for the name-based setter, which is the natural one to use since it is the only API that resolves a morph by name.

Route both overloads through getMorphState(), which already allocates on demand, so the by-name and by-array paths behave alike. The lookup guard is unchanged: an unknown name still writes nothing and reads -1.

Geometry allocates its morphState array lazily. setMorphState(float[]) and
getMorphState() both create it on demand, but the name-based overloads
setMorphState(String, float) and getMorphState(String) indexed the field
directly, so calling either one first threw NullPointerException:

    java.lang.NullPointerException: Cannot store to float array because
    "this.morphState" is null

Nothing else populates the array. MorphControl only reads it, and the
control itself is attached by GltfLoader only when the asset carries an
animation channel targeting "weights". An application driving morph targets
from its own code -- expression blending, a slider, anything procedural --
therefore has an unallocated array precisely when it reaches for the
name-based setter, which is the natural one to use since it is the only API
that resolves a morph by name.

Route both overloads through getMorphState(), which already allocates on
demand, so the by-name and by-array paths behave alike. The lookup guard is
unchanged: an unknown name still writes nothing and reads -1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant