program not respnding[corrected]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

program not respnding[corrected]

Post by omar shaaban »

in my program compiled with Msvc++2008 and irrlicht1.5 in code blocks
this code works fine :

Code: Select all

SPhysxAndNodePair* mag;

 "some where in main()"
mag = new SPhysxAndNodePair[999];

    for(int i=0;i<20;i++)
      {
          for(int j=0;j<20;j++)
      {
cout<<"test1";
mag[id].PhysxObject = physxManager->createSphereObject(core::vector3df(i*tilesize,j*tilesize,z*tilesize), core::vector3df(0,0,0), tilesize/2, 1.0f, NULL);
	cout<<"test 2 \n";
	mag[id].SceneNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("par.3ds"));
	mag[id].SceneNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
      mag[id].SceneNode->setMaterialFlag(EMF_LIGHTING, false);
  }}
the program works correctly
but when i change

Code: Select all

SPhysxAndNodePair* mag;
to this line

Code: Select all

SPhysxAndNodePair mag[999];
and i delete

Code: Select all

mag = new SPhysxAndNodePair[999];
it doesnt give me any errors!!!
but when theprogram is excuted it doesnt stop , you willfind in the code to output to the console which are
"test1" and "test 2"
only text1 appears that means that the program stops at this line:

Code: Select all

mag[id].PhysxObject = physxManager->createSphereObject(core::vector3df(i*tilesize,j*tilesize,z*tilesize), core::vector3df(0,0,0), tilesize/2, 1.0f, NULL)
i understand that i changed mag from being a pointer but when i declare it in the for of array it should be the same
like for example:

Code: Select all

int array[99]
is the same as:

Code: Select all

int*array=new int[99]
so it should be the same way!!
any help?
-insane-
Posts: 18
Joined: Tue Aug 04, 2009 4:41 pm
Location: Germany

Post by -insane- »

Maybe it's because mag isn't initialized.

Try this:

Code: Select all

for (int i = 0; i < 999; i++)
    ZeroMemory (&mag[i], sizeof(SPhysxAndNodePair));
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

-insane- wrote:

Code: Select all

for (int i = 0; i < 999; i++) 
    ZeroMemory (&mag[i], sizeof(SPhysxAndNodePair));
This is dangerous if SPhysxAndNodePair is a class type that has a non-trivial constructor or destructor. I'm not certain that this is safe given the code that we've seen so far.

Travis
Post Reply