From 4fb6ba58c71f998d1f05d8faba7b97b281a1850c Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Tue, 28 Aug 2012 10:10:42 +0000 Subject: [PATCH] Fix to colorband loading. Preventing a crash when less than 4 cursors are used. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9691 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../plugins/blender/textures/ColorBand.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/ColorBand.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/ColorBand.java index 1ce8cb737..4a5131af2 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/ColorBand.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/ColorBand.java @@ -154,10 +154,10 @@ public class ColorBand { float[] ipoFactors = new float[4]; float f; - ColorBandData data0 = cbDataMap.get(currentCursor - 2); - ColorBandData data1 = cbDataMap.get(currentCursor - 1); - ColorBandData data2 = cbDataMap.get(currentCursor); - ColorBandData data3 = cbDataMap.get(currentCursor + 1); + ColorBandData data0 = this.getColorbandData(currentCursor - 2, cbDataMap); + ColorBandData data1 = this.getColorbandData(currentCursor - 1, cbDataMap); + ColorBandData data2 = this.getColorbandData(currentCursor, cbDataMap); + ColorBandData data3 = this.getColorbandData(currentCursor + 1, cbDataMap); for (int i = 0; i < result.length; ++i) { if (data2.pos != data1.pos) { @@ -234,6 +234,14 @@ public class ColorBand { } return result; } + + private ColorBandData getColorbandData(int index, Map cbDataMap) { + ColorBandData result = cbDataMap.get(index); + if(result == null) { + result = new ColorBandData(); + } + return result; + } /** * This method returns the data for either B-spline of Cardinal @@ -272,6 +280,11 @@ public class ColorBand { public final float r, g, b, a; public int pos; + public ColorBandData() { + r = g = b = 0; + a = 1; + } + /** * Copy constructor. */