Page 1 of 1

Loads of btRigidBody's gives stackoverflowerror

Posted: Mon Oct 21, 2013 6:48 am
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.

Re: Loads of btRigidBody's gives stackoverflowerror

Posted: Mon Oct 21, 2013 9:11 am
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*
	}
}