Loads of btRigidBody's gives stackoverflowerror

Post Reply
skiwi
Posts: 2
Joined: Sat Oct 19, 2013 5:43 pm

Loads of btRigidBody's gives stackoverflowerror

Post by skiwi »

I am trying to allocate memory for 90.000 btRigidBody's, but it is giving me stackoverflowerror, it supposedly is coming from the fact that it is asking too much non-dynamically allocated memory.

Current code:

Code: Select all

btRigidBody* tileRigidBody[300][300]
How I read I should dynamically allocate with integers:

Code: Select all

int* intarray = new int[10]
Would dynamic allocation fix the issue + how can I do it for btRigidBody, as it is giving me an issue that no constructor exists.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Loads of btRigidBody's gives stackoverflowerror

Post by c6burns »

Well there's no default constructor, which is why you can't just allocate them like you are trying with new. There's probably a cleaner way to do this with std containers, which you should look into ... I'm more of a C guy and this is basically what C++ inherited from C.

Single dimension of btRigidBody:

Code: Select all

btRigidBody **rbArray = new btRigidBody*[300]; //returns a pointer to a btRigidBody*
for (int x=0;x<300;x++) rbArray[x] = new btRigidBody(/* constructor arguments here */); //returns a btRigidBody*
Multi-dimension:

Code: Select all

btRigidBody ***rbArray = new btRigidBody**[300]; //returns a pointer to a btRigidBody** ... double pointer so intense
for (int x = 0; x < 300; x++) {
	rbArray[x] = new btRigidBody*[300]; //returns a pointer to a btRigidBody*
	for (int y = 0; y < 300; y++) {
		rbArray[x][y] = new btRigidBody(/* constructor arguments here */); //returns a btRigidBody*
	}
}
Post Reply