Hi,
I added thirdparty library as a plugin in unreal (Bullet Physics. Not a replacement of physx just for some functions). But when i use my working code in unreal it gives “unable to read memory” errors.
When i debug it i see unable to read memory errors on variables, actors …
So i am thinking maybe Bullets memory management collides with unreals. Bullet uses 16byte alignment. Is this can be source of problem ? Maybe if i tell bullet use same alignment as unreal this can be solution to this problem ?
// Fill out your copyright notice in the Description page of Project Settings.
#include "SharpSurgeon.h"
#include "TestActor.h"
#include "btBulletDynamicsCommon.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
#include "BulletSoftBody/btDefaultSoftBodySolver.h"
#include "BulletSoftBody/btSoftBodyHelpers.h"
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
struct bulletObject {
int id;
float r, g, b;
bool hit;
btRigidBody* body;
bulletObject(btRigidBody* b, int i, float r0, float g0, float b0) : body(b), id(i), r(r0), g(g0), b(b0), hit(false) {}
};
btSoftRigidDynamicsWorld* world;
btDispatcher* dispatcher;
btCollisionConfiguration* collisionConfig;
btBroadphaseInterface* broadphase;
btConstraintSolver* solver;
btSoftBodySolver* softbodySolver;
TArray<bulletObject*> bodies;
btSoftBody* softBody;
btTransform t;
btMotionState* motion;
btStaticPlaneShape* plane;
btRigidBody* body;
btRigidBody::btRigidBodyConstructionInfo info(0.0, motion, plane);
// Sets default values
ATestActor::ATestActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ATestActor::BeginPlay()
{
Super::BeginPlay();
collisionConfig = new btSoftBodyRigidBodyCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfig);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
softbodySolver = new btDefaultSoftBodySolver();
world = new btSoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfig, softbodySolver);
world->setGravity(btVector3(0, -10, 0));
t.setIdentity();
t.setOrigin(btVector3(0, 0, 0));
plane = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
motion = new btDefaultMotionState(t);
body = new btRigidBody(info);
world->addRigidBody(body);
bodies.Add(new bulletObject(body, 4, 0.8, 0.8, 0.8));
body->setUserPointer(bodies[bodies.Num() - 1]);
float s = 4;
float h = 20;
softBody = btSoftBodyHelpers::CreateEllipsoid(world->getWorldInfo(),
btVector3(10, 10, 10), btVector3(2, 2, 2), 1000);
softBody->m_cfg.viterations = 50;
softBody->m_cfg.piterations = 50;
softBody->m_cfg.kPR = 1000;
softBody->setTotalMass(3.0);
softBody->setMass(0, 0);
world->addSoftBody(softBody);
}
// Called every frame
void ATestActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
world->stepSimulation(DeltaTime);
}
Best,
Korcan