From 20c5994db482582322efd82076456cc14569b789 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Sun, 16 Oct 2011 02:06:58 +0000 Subject: [PATCH] - native bullet: add some checks to physics space and physics vehicle git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8410 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../bullet/native/com_jme3_bullet_PhysicsSpace.cpp | 3 +++ .../com_jme3_bullet_objects_PhysicsVehicle.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp b/engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp index 1801e8afb..01c438193 100644 --- a/engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp +++ b/engine/src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp @@ -390,6 +390,9 @@ extern "C" { JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative (JNIEnv * env, jobject object, jlong spaceId) { jmePhysicsSpace* space = (jmePhysicsSpace*) spaceId; + if (space == NULL) { + return; + } delete(space); } diff --git a/engine/src/bullet/native/com_jme3_bullet_objects_PhysicsVehicle.cpp b/engine/src/bullet/native/com_jme3_bullet_objects_PhysicsVehicle.cpp index db4a54bb7..d7f51f7c1 100644 --- a/engine/src/bullet/native/com_jme3_bullet_objects_PhysicsVehicle.cpp +++ b/engine/src/bullet/native/com_jme3_bullet_objects_PhysicsVehicle.cpp @@ -67,6 +67,7 @@ extern "C" { JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_createVehicleRaycaster (JNIEnv *env, jobject object, jlong bodyId, jlong spaceId) { //btRigidBody* body = (btRigidBody*) bodyId; + jmeClasses::initJavaClasses(env); jmePhysicsSpace *space = (jmePhysicsSpace *)spaceId; if (space == NULL) { jclass newExc = env->FindClass("java/lang/NullPointerException"); @@ -84,6 +85,7 @@ extern "C" { */ JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_createRaycastVehicle (JNIEnv *env, jobject object, jlong objectId, jlong casterId) { + jmeClasses::initJavaClasses(env); btRigidBody* body = (btRigidBody*) objectId; if (body == NULL) { jclass newExc = env->FindClass("java/lang/NullPointerException"); @@ -92,6 +94,11 @@ extern "C" { } body->setActivationState(DISABLE_DEACTIVATION); btVehicleRaycaster* caster = (btDefaultVehicleRaycaster*) casterId; + if (caster == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return 0; + } btRaycastVehicle::btVehicleTuning tuning; btRaycastVehicle* vehicle = new btRaycastVehicle(tuning, body, caster); return (long) vehicle; @@ -250,6 +257,11 @@ extern "C" { return; } delete(vehicle); + if (rayCaster == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } delete(rayCaster); }