Hi!
The game I’m working on always crashes at the same point, when I’m looking at a Spatial.
More I can’t tell about that problem, the game ends and I get that error:
java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1. Because at most 1 elements can be returned, a buffer with at least 1 elements is required, regardless of actual returned element count
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:258)
at org.lwjgl.opengl.GL15.glBufferData(GL15.java:155)
at com.jme3.renderer.lwjgl.LwjglRenderer.updateBufferData(LwjglRenderer.java:2054)
at com.jme3.renderer.lwjgl.LwjglRenderer.setVertexAttrib(LwjglRenderer.java:2182)
at com.jme3.renderer.lwjgl.LwjglRenderer.setVertexAttrib(LwjglRenderer.java:2217)
at com.jme3.renderer.lwjgl.LwjglRenderer.renderMeshDefault(LwjglRenderer.java:2422)
at com.jme3.renderer.lwjgl.LwjglRenderer.renderMesh(LwjglRenderer.java:2469)
at com.jme3.material.Material.render(Material.java:1103)
at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:658)
at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:301)
at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:350)
at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:919)
at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:850)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1126)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1174)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:254)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:722)
The Spatial itself seems to be okay, it’s loaded fine and i can see it before the game stops…
It definitely to do with that code snippet:
[java]
if (doorSpatial.getLocalTranslation().distance(cam.getLocation()) < 15 && “Dungeon Entrance”.equals(getPointedTarget())) {
actionText.setText("[E] Open the door");
} else {
actionText.setText("");
}
}
[/java]
The method getPointedTarget():
[java]
CollisionResults results;
Ray ray;
String targetName;
float dist;
Vector3f pt;
Geometry target;
private String getPointedTarget() {
results = new CollisionResults();
ray = new Ray(cam.getLocation(), cam.getDirection());
rootNode.collideWith(ray, results);
for (int i = 1; i < results.size(); i++) {
dist = results.getCollision(i).getDistance();
pt = results.getCollision(i).getContactPoint();
targetName = results.getCollision(i).getGeometry().getName();
}
target = null;
if (results.size() > 0) {
target = results.getClosestCollision().getGeometry();
targetName = target.getName();
System.out.println(targetName);
}
return targetName;
}
[/java]
because when I comment it out, the application runs fine.
Any ideas?
The exception is not pointing at my code directly, what’s going wrong?
I got it, it’s just because of the line
[java]actionText.setText("");[/java]
No characters, that caused the error.
changed it to
[java]actionText.setText(" ");[/java]
What is actionText?
A BitmapText.
It shows the action + the button to interact with sth.
for e.x.: [E] Open the door
Hmmm… BitmapText shouldn’t fail with an empty string. May be a bug.
If you can put together a simple test case illustrating the problem then it will help whoever gets time to fix this.
I looked into it, I have a fix I’m about to commit…
Here is a test case for the problem. Hold the TAB key to see the text disappear, release to see some text come back.
[java]
/*
- Copyright © 2009-2010 jMonkeyEngine
- All rights reserved.
*
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
*
-
- Redistributions of source code must retain the above copyright
- Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
*
-
- Redistributions in binary form must reproduce the above copyright
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
*
-
- Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
- Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
*
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/
package jme3test.gui;
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.font.LineWrapMode;
import com.jme3.font.Rectangle;
import com.jme3.input.KeyInput;
import com.jme3.input.RawInputListener;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.event.;
public class TestBitmapFont extends SimpleApplication {
private String txtB =
“ABCDEFGHIKLMNOPQRSTUVWXYZ1234567 890`~!@#$%^&*()-=_+[];’,./{}|:<>?”;
private BitmapText txt;
private BitmapText txt2;
private BitmapText txt3;
public static void main(String[] args){
TestBitmapFont app = new TestBitmapFont();
app.start();
}
@Override
public void simpleInitApp() {
inputManager.addMapping(“WordWrap”, new KeyTrigger(KeyInput.KEY_TAB));
inputManager.addListener(keyListener, “WordWrap”);
inputManager.addRawInputListener(textListener);
BitmapFont fnt = assetManager.loadFont(“Interface/Fonts/Default.fnt”);
txt = new BitmapText(fnt, false);
txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
txt.setSize(fnt.getPreferredSize() * 2f);
txt.setText(txtB);
txt.setLocalTranslation(0, txt.getHeight(), 0);
guiNode.attachChild(txt);
txt2 = new BitmapText(fnt, false);
txt2.setSize(fnt.getPreferredSize() * 1.2f);
txt2.setText(“Text without restriction. nText without restriction. Text without restriction. Text without restriction”);
txt2.setLocalTranslation(0, txt2.getHeight(), 0);
guiNode.attachChild(txt2);
txt3 = new BitmapText(fnt, false);
txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
txt3.setText(“Press Tab to toggle word-wrap. type text and enter to input text”);
txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
guiNode.attachChild(txt3);
}
private ActionListener keyListener = new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if(txt.getText().equals("")){
txt.setText(“Hi”);
}
else{
txt.setText("");
}
}
};
private RawInputListener textListener = new RawInputListener() {
private StringBuilder str = new StringBuilder();
@Override
public void onMouseMotionEvent(MouseMotionEvent evt) { }
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) { }
@Override
public void onKeyEvent(KeyInputEvent evt) {
if (evt.isReleased())
return;
if (evt.getKeyChar() == ‘n’ || evt.getKeyChar() == ‘r’) {
txt3.setText(str.toString());
str.setLength(0);
} else {
str.append(evt.getKeyChar());
}
}
@Override
public void onJoyButtonEvent(JoyButtonEvent evt) { }
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) { }
@Override
public void endInput() { }
@Override
public void beginInput() { }
@Override
public void onTouchEvent(TouchEvent evt) { }
};
}
[/java]
ok, the fix is committed in revisions 9389 and 9390.
http://code.google.com/p/jmonkeyengine/source/detail?r=9389
http://code.google.com/p/jmonkeyengine/source/detail?r=9390
Cool thanks :), I looked at the diffs and I think:
L139 you should get rid of - [java]System.out.println("Creating new StringBlock and Letters"); [/java] in BitmapText.java
L93 - I also agree getting rid of [java]if (arrayBased)[/java] in BitmapTextPage.java
@wezrule said:L139 you should get rid of - [java]System.out.println("Creating new StringBlock and Letters"); [/java] in BitmapText.java
Yeah, thanks.. Already took all the debugging stuff out a little while ago.. r9391 and 9392
ah right