Rotation related crash in native code (LWJGL Rendering Thread)

I have noticed a problem with rotations. My app i based on the Terrain Collision example and i have attached a spatial (a sword if you’re interested) that i want to appear to be held by the player. But when i use sword.rotate() or rotates the camera upwards until i flip over and the world is upside down the application crashed in native code. Here is javas crash log:

[java]#

A fatal error has been detected by the Java Runtime Environment:

#

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x044490ef, pid=5004, tid=2700

#

JRE version: 6.0_22-b04

Java VM: Java HotSpot™ Client VM (17.1-b03 mixed mode, sharing windows-x86 )

Problematic frame:

C [ig4icd32.dll+0x1390ef]

#

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

#


T H R E A D

Current thread (0x03ee9400): JavaThread "LWJGL Renderer Thread" [_thread_in_native, id=2700, stack(0x04090000,0x040e0000)]

siginfo: ExceptionCode=0xc0000005, reading address 0x0bf24000

Registers:
EAX=0x0bf24000, EBX=0x047b37b0, ECX=0x00000002, EDX=0x00000001
ESP=0x040df420, EBP=0x040df448, ESI=0x00000060, EDI=0x00000046
EIP=0x044490ef, EFLAGS=0x00210293

Top of Stack: (sp=0x040df420)
0x040df420: 00000046 00265d7c 00000060 047e80df
0x040df430: 0000000c 044478f3 00000001 00000001
0x040df440: 00000045 00265d7c 066092d8 04449655
0x040df450: 00265d7c 047b37b0 00000046 066095b8
0x040df460: 002c9db0 00265d7c 0026027f 00265d7c
0x040df470: 00080038 066506f0 05c46ef8 0435cff9
0x040df480: 00265d7c 05c46ef8 00000001 0026007f
0x040df490: 00080038 04813f00 05cef7c0 00265d7c

Instructions: (pc=0x044490ef)
0x044490df: 04 f3 0f 11 41 08 f3 0f 11 49 0c e9 43 01 00 00
0x044490ef: 8b 10 c1 e1 04 03 cb 89 11 8b 40 04 89 41 04 f3


Stack: [0x04090000,0x040e0000], sp=0x040df420, free space=13d040def3ck
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ig4icd32.dll+0x1390ef]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J org.lwjgl.opengl.GL12.nglDrawRangeElementsBO(IIIIIJJ)V
J org.lwjgl.opengl.GL12.glDrawRangeElements(IIIIIJ)V
J com.jme3.renderer.lwjgl.LwjglRenderer.drawTriangleList(Lcom/jme3/scene/VertexBuffer;Lcom/jme3/scene/Mesh;I)V
J com.jme3.renderer.lwjgl.LwjglRenderer.renderMeshDefault(Lcom/jme3/scene/Mesh;II)V
J com.jme3.renderer.lwjgl.LwjglRenderer.renderMesh(Lcom/jme3/scene/Mesh;II)V
J com.jme3.material.Material.render(Lcom/jme3/scene/Geometry;Lcom/jme3/renderer/RenderManager;)V
J com.jme3.renderer.RenderManager.renderGeometry(Lcom/jme3/scene/Geometry;)V
J com.jme3.renderer.queue.RenderQueue.renderGeometryList(Lcom/jme3/renderer/queue/GeometryList;Lcom/jme3/renderer/RenderManager;Lcom/jme3/renderer/Camera;Z)V
j com.jme3.renderer.queue.RenderQueue.renderQueue(Lcom/jme3/renderer/queue/RenderQueue$Bucket;Lcom/jme3/renderer/RenderManager;Lcom/jme3/renderer/Camera;Z)V+64
j com.jme3.renderer.RenderManager.renderViewPortQueues(Lcom/jme3/renderer/ViewPort;Z)V+22
j com.jme3.renderer.RenderManager.flushQueue(Lcom/jme3/renderer/ViewPort;)V+3
j com.jme3.renderer.RenderManager.renderViewPort(Lcom/jme3/renderer/ViewPort;F)V+238
j com.jme3.renderer.RenderManager.render(F)V+72
j com.jme3.app.SimpleApplication.update()V+158
j com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop()V+22
j com.jme3.system.lwjgl.LwjglDisplay.runLoop()V+67
j com.jme3.system.lwjgl.LwjglAbstractDisplay.run()V+100
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub

P R O C E S S

Java Threads: ( => current thread )
0x06f38400 JavaThread "Thread-3" daemon [_thread_blocked, id=4548, stack(0x05000000,0x05050000)]
0x06f38800 JavaThread "AWT-Windows" daemon [_thread_in_native, id=5812, stack(0x08b20000,0x08b70000)]
0x06f44000 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=5748, stack(0x084c0000,0x08510000)]
0x00359c00 JavaThread "DestroyJavaVM" [_thread_blocked, id=5296, stack(0x00170000,0x001c0000)]
=>0x03ee9400 JavaThread "LWJGL Renderer Thread" [_thread_in_native, id=2700, stack(0x04090000,0x040e0000)]
0x01a68000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=1408, stack(0x03df0000,0x03e40000)]
0x01a5ac00 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4736, stack(0x03da0000,0x03df0000)]
0x01a59c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=4312, stack(0x03d50000,0x03da0000)]
0x01a56c00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=1372, stack(0x03d00000,0x03d50000)]
0x01a16c00 JavaThread "Finalizer" daemon [_thread_blocked, id=4804, stack(0x03cb0000,0x03d00000)]
0x01a12400 JavaThread "Reference Handler" daemon [_thread_blocked, id=2708, stack(0x03c60000,0x03cb0000)]

Other Threads:
0x01a11000 VMThread [stack: 0x03c10000,0x03c60000] [id=1368]
0x01a69c00 WatcherThread [stack: 0x03e40000,0x03e90000] [id=4456]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
def new generation total 4992K, used 970K [0x23ba0000, 0x24100000, 0x290f0000)
eden space 4480K, 16% used [0x23ba0000, 0x23c59bf0, 0x24000000)
from space 512K, 44% used [0x24000000, 0x24038e18, 0x24080000)
to space 512K, 0% used [0x24080000, 0x24080000, 0x24100000)
tenured generation total 10944K, used 9187K [0x290f0000, 0x29ba0000, 0x33ba0000)
the space 10944K, 83% used [0x290f0000, 0x299e8c00, 0x299e8c00, 0x29ba0000)
compacting perm gen total 12288K, used 4542K [0x33ba0000, 0x347a0000, 0x37ba0000)
the space 12288K, 36% used [0x33ba0000, 0x3400fbb0, 0x3400fc00, 0x347a0000)
ro space 10240K, 54% used [0x37ba0000, 0x3811c510, 0x3811c600, 0x385a0000)
rw space 12288K, 55% used [0x385a0000, 0x38c3fb78, 0x38c3fc00, 0x391a0000)

Dynamic libraries:
0x00400000 - 0x00424000 C:Program FilesJavajdk1.6.0_22jrebinjava.exe
0x779f0000 - 0x77b2c000 C:WindowsSYSTEM32ntdll.dll
0x75fc0000 - 0x76094000 C:Windowssystem32kernel32.dll
0x75cd0000 - 0x75d1a000 C:Windowssystem32KERNELBASE.dll
0x75eb0000 - 0x75f50000 C:Windowssystem32ADVAPI32.dll
0x763f0000 - 0x7649c000 C:Windowssystem32msvcrt.dll
0x75e80000 - 0x75e99000 C:WindowsSYSTEM32sechost.dll
0x76580000 - 0x76621000 C:Windowssystem32RPCRT4.dll
0x7c340000 - 0x7c396000 C:Program FilesJavajdk1.6.0_22jrebinmsvcr71.dll
0x6d8a0000 - 0x6db47000 C:Program FilesJavajdk1.6.0_22jrebinclientjvm.dll
0x77b50000 - 0x77c19000 C:Windowssystem32USER32.dll
0x75f50000 - 0x75f9e000 C:Windowssystem32GDI32.dll
0x75fb0000 - 0x75fba000 C:Windowssystem32LPK.dll
0x76160000 - 0x761fd000 C:Windowssystem32USP10.dll
0x74310000 - 0x74342000 C:Windowssystem32WINMM.dll
0x77b30000 - 0x77b4f000 C:Windowssystem32IMM32.DLL
0x764b0000 - 0x7657c000 C:Windowssystem32MSCTF.dll
0x75a70000 - 0x75abb000 C:Windowssystem32apphelp.dll
0x6d850000 - 0x6d85c000 C:Program FilesJavajdk1.6.0_22jrebinverify.dll
0x6d3d0000 - 0x6d3ef000 C:Program FilesJavajdk1.6.0_22jrebinjava.dll
0x6d330000 - 0x6d338000 C:Program FilesJavajdk1.6.0_22jrebinhpi.dll
0x764a0000 - 0x764a5000 C:Windowssystem32PSAPI.DLL
0x6d890000 - 0x6d89f000 C:Program FilesJavajdk1.6.0_22jrebinzip.dll
0x10000000 - 0x10047000 C:UsersntijMonkeyProjectsTales of Endrolothlwjgl.dll
0x040e0000 - 0x041a8000 C:Windowssystem32OPENGL32.dll
0x6f0f0000 - 0x6f112000 C:Windowssystem32GLU32.dll
0x727c0000 - 0x728a7000 C:Windowssystem32DDRAW.dll
0x72c80000 - 0x72c86000 C:Windowssystem32DCIMAN32.dll
0x76630000 - 0x767cd000 C:Windowssystem32SETUPAPI.dll
0x75c70000 - 0x75c97000 C:Windowssystem32CFGMGR32.dll
0x76360000 - 0x763ef000 C:Windowssystem32OLEAUT32.dll
0x76200000 - 0x7635c000 C:Windowssystem32ole32.dll
0x75c50000 - 0x75c62000 C:Windowssystem32DEVOBJ.dll
0x74ec0000 - 0x74ed3000 C:Windowssystem32dwmapi.dll
0x74da0000 - 0x74da9000 C:Windowssystem32VERSION.dll
0x74f10000 - 0x750ae000 C:WindowsWinSxSx86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bdCOMCTL32.dll
0x77850000 - 0x778a7000 C:Windowssystem32SHLWAPI.dll
0x74730000 - 0x74770000 C:Windowssystem32uxtheme.dll
0x04310000 - 0x04702000 C:Windowssystem32ig4icd32.dll
0x047c0000 - 0x04a5a000 C:Windowssystem32ig4dev32.dll
0x75ac0000 - 0x75acc000 C:Windowssystem32CRYPTBASE.dll
0x760d0000 - 0x76153000 C:Windowssystem32CLBCatQ.DLL
0x649c0000 - 0x64a39000 C:Windowssystem32mscms.dll
0x75100000 - 0x75117000 C:Windowssystem32USERENV.dll
0x75b40000 - 0x75b4b000 C:Windowssystem32profapi.dll
0x6f070000 - 0x6f0a8000 C:Windowssystem32icm32.dll
0x6d0b0000 - 0x6d1fa000 C:Program FilesJavajdk1.6.0_22jrebinawt.dll
0x71220000 - 0x71271000 C:Windowssystem32WINSPOOL.DRV
0x07610000 - 0x0764a000 C:UsersntijMonkeyProjectsTales of EndrolothOpenAL32.dll
0x6fb90000 - 0x6fc33000 C:WindowsWinSxSx86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cbMSVCR90.dll
0x76ba0000 - 0x777e9000 C:Windowssystem32SHELL32.dll
0x66700000 - 0x66772000 C:Windowssystem32dsound.dll
0x74920000 - 0x74945000 C:Windowssystem32POWRPROF.dll
0x748e0000 - 0x74919000 C:WindowsSystem32MMDevApi.dll
0x747e0000 - 0x748d5000 C:WindowsSystem32PROPSYS.dll
0x73b00000 - 0x73b36000 C:Windowssystem32AUDIOSES.DLL
0x747b0000 - 0x747b7000 C:Windowssystem32avrt.dll
0x6d4f0000 - 0x6d515000 C:Program FilesJavajdk1.6.0_22jrebinjpeg.dll
0x6d2e0000 - 0x6d32f000 C:Program FilesJavajdk1.6.0_22jrebinfontmanager.dll

VM Arguments:
jvm_args: -Dfile.encoding=UTF-8
java_command: mygame.Main
Launcher Type: SUN_STANDARD

Environment Variables:
PATH=C:Program FilesCommon FilesMicrosoft SharedWindows Live;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesWindows LiveShared;c:Program FilesMicrosoft SQL Server100ToolsBinn;c:Program FilesMicrosoft SQL Server100DTSBinn;C:Program FilesTortoiseSVNbin;C:Program FilesNVIDIA CorporationCgbin;C:Program FilesMicrosoft Windows Performance Toolkit;C:Program FilesNmap
USERNAME=nti
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 6, GenuineIntel



S Y S T E M

OS: Windows 7 Build 7600

CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 23 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1

Memory: 4k page, physical 2087216k(815064k free), swap 4174432k(2195920k free)

vm_info: Java HotSpot(TM) Client VM (17.1-b03) for windows-x86 JRE (1.6.0_22-b04), built on Sep 15 2010 00:56:36 by "java_re" with MS VC++ 7.1 (VS2003)

time: Tue Nov 23 19:56:18 2010
elapsed time: 3 seconds

[/java]

I have no idea what the problem might be. If i use sword.rotate() the app runs for a second or two, and then crashes. Below is my full source code if it is my fault.
[java]package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.app.SimpleBulletApplication;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.nodes.PhysicsCharacterNode;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.heightmap.AbstractHeightMap;
import com.jme3.terrain.heightmap.ImageBasedHeightMap;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.util.SkyFactory;
import java.util.ArrayList;
import java.util.List;
import jme3tools.converters.ImageToAwt;

public class Main extends SimpleBulletApplication {

private TerrainQuad terrain;
PhysicsCharacterNode player;
Boolean left = false, right = false, up = false, down = false, running = false, autoRun = false;
private Vector3f walkDirection = new Vector3f();
Spatial sword = null;
Node camPivot = new Node("camPivot");

public static void main(String[] args) {
Main app = new Main();

app.setShowSettings(false);

AppSettings cfg = new AppSettings(true);
cfg.setBitsPerPixel(24);
cfg.setFullscreen(false);
cfg.setHeight(600);
cfg.setWidth(800);
cfg.setResolution(800, 600);
cfg.setVSync(false);
app.setSettings(cfg);

app.setPauseOnLostFocus(true);

app.start();
}

@Override
public void simpleInitApp() {
setupKeys();
setupPlayer();

guiNode.detachAllChildren();

Material terrain_mat;
PhysicsNode landscape;

/** 1. Create terrain material and load four textures into it. */
terrain_mat = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");

/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
terrain_mat.setTexture("m_Alpha", assetManager.loadTexture("Textures/hm1_alpha.png"));

/** 1.2) Add GRASS texture into the red layer (m_Tex1). */
Texture grass = assetManager.loadTexture("Textures/grass.jpg");
grass.setWrap(WrapMode.Repeat);
terrain_mat.setTexture("m_Tex1", grass);
terrain_mat.setFloat("m_Tex1Scale", 64f);

/** 1.3) Add DIRT texture into the green layer (m_Tex2) */
Texture dirt = assetManager.loadTexture("Textures/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
terrain_mat.setTexture("m_Tex2", dirt);
terrain_mat.setFloat("m_Tex2Scale", 32f);

/** 1.4) Add ROAD texture into the blue layer (m_Tex3) */
Texture rock = assetManager.loadTexture("Textures/road.jpg");
rock.setWrap(WrapMode.Repeat);
terrain_mat.setTexture("m_Tex3", rock);
terrain_mat.setFloat("m_Tex3Scale", 128f);

/** 2. Create the height map */
AbstractHeightMap heightmap = null;
Texture heightMapImage = assetManager.loadTexture("Textures/hm1.png");
heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
heightmap.load();

terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());

HeightfieldCollisionShape sceneShape = new HeightfieldCollisionShape(heightmap.getHeightMap());
landscape = new PhysicsNode(terrain, sceneShape, 0);

/** 4. The LOD (level of detail) depends on were the camera is: */
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(getCamera());
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
terrain.addControl(control);

/** 5. We give the terrain its material, position & scale it, and attach it. */
terrain.setMaterial(terrain_mat);
landscape.setLocalTranslation(0, -100, 0);
rootNode.attachChild(landscape);
getPhysicsSpace().add(landscape);

rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Skysphere.jpg", true));

sword = assetManager.loadModel("Models/sword.obj");
sword.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"));
camPivot.attachChild(sword);
sword.scale(0.01f);
sword.setLocalTranslation(0.0f, 0.0f, 10.0f);
sword.rotate(-1.9f, 0.0f, 0.0f);
rootNode.attachChild(camPivot);

cam.setFrustumNear(1.0f);
}

@Override
public void simpleUpdate(float tpf) {

System.out.println(player.getLocalTranslation().toString());
System.out.println(sword.getLocalTranslation().toString());
System.out.println("");

camPivot.setLocalTranslation(player.getLocalTranslation());
camPivot.setLocalRotation(cam.getRotation());

Vector3f camDir = cam.getDirection().clone().multLocal(0.1f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.05f);

if(running || autoRun) {
camDir = camDir.mult(2.5f);
camLeft = camLeft.mult(2.5f);
}

walkDirection.set(0, 0, 0);

if(autoRun) {
walkDirection.addLocal(camDir);
}

if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
walkDirection.y = 0;
}
if (down) {
walkDirection.addLocal(camDir.negate());
walkDirection.y = 0;
}
player.setWalkDirection(walkDirection);
cam.setLocation(player.getLocalTranslation());
}

public void setupPlayer() {
player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.2f, 3f, 1), .05f);
player.setJumpSpeed(20); //10 default
player.setFallSpeed(70); //30 default
player.setGravity(50); //30 default
player.setLocalTranslation(new Vector3f(0f, 250f, 150f));
rootNode.attachChild(player);
getPhysicsSpace().add(player);
}

private void setupKeys() {
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("Run", new KeyTrigger(KeyInput.KEY_LSHIFT));
inputManager.addMapping("AutoRun", new KeyTrigger(KeyInput.KEY_CAPITAL));
inputManager.addListener(actionListener, new String[]{"Left", "Right", "Up", "Down", "Jump", "Run", "AutoRun"});
}
private ActionListener actionListener = new ActionListener() {

public void onAction(String binding, boolean keyPressed, float tpf) {
if (binding.equals("Left")) {
if (keyPressed /*&& player.onGround()*/) {
left = true;
} else {
left = false;
}
} else if (binding.equals("Right")) {
if (keyPressed /*&& player.onGround()*/) {
right = true;
} else {
right = false;
}
} else if (binding.equals("Up")) {
if (keyPressed /*&& player.onGround()*/) {
up = true;
autoRun = false;
} else {
up = false;
}
} else if (binding.equals("Down")) {
if (keyPressed /*&& player.onGround()*/) {
down = true;
autoRun = false;
} else {
down = false;
}
} else if (binding.equals("Jump") && player.onGround()) {
player.jump();
} else if(binding.equals("Run")) {
if(keyPressed) {
running = true;
} else {
running = false;
}
} else if(binding.equals("AutoRun") && keyPressed) {
autoRun = !autoRun;
}
}
};
}[/java]

Looks like a driver issue. Make sure you have the latest driver.

If the issue is still happening, you can try to isolate it by removing as much code as possible until you have the exact thing that causes the crash.