Keeping track of bullet particles before/after collision

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.
marrabld
Posts: 37
Joined: Wed Jul 11, 2007 9:16 am

Post by marrabld »

OK I am on the home straight.

I have got to the point where I am trying to destroy my enemies ;) when a bullet collides with them.

I have can successfully get cout<<"Collision!"<<endl; when they collide but when try the next step;

Code: Select all

if(ScalarDistance < bound)
{
    cout<<"Collision!"<<endl;
    ememy[i].anms->drop();
}
I get a segmentation fault. I think it might be because I am trying to delete an animator while the Irrlicht animator is using it to animate the model (true??)

I tried;

Code: Select all

if(ScalarDistance < bound)
{
    cout<<"Collision!"<<endl;
    enemy[i].anms-grab();
    ememy[i].anms->drop();
}
It doesn't segfault but it doesn't remove my enemy.

anyone know how to do what I am trying to achieve.

NOTE:

I create the sydney model the same way the tutorials do and but use enemy.anms = blah blah.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Use

ememy.anms->remove();
marrabld
Posts: 37
Joined: Wed Jul 11, 2007 9:16 am

Post by marrabld »

Thanks Eigen for the reply,

But not joy, gives me the same error. This one has really got me stumped.

SegFault usually means you are trying to access some memory that you aren't supposed to right?

Could I have set up the anms incorrectly? I have checked my code, it is done the same as in the '04 Movement' tutorial. Is it done is such a way that I cant do what I am attempting?

So I tried making sydney as mettioned. and then immediately (the next line) after the line

Code: Select all

enemy[ENEMY_ID].anms->setMaterialTexture(blah);
I tried

Code: Select all

enemy[ENEMY_ID].anms->remove();//and ->drop();
She flashes onto the screen for a microsecond before segfaulting.

this confuses me :?

Any Ideas on what I could try to attempt a diagnosis?
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Could you perhaps show the exact code you use to create the enemy, and also your struct or class you use for the enemies.
marrabld
Posts: 37
Joined: Wed Jul 11, 2007 9:16 am

Post by marrabld »

OK,

i have attached a create enemy method to a key in my event handler for testing purposes

Code: Select all

void DansGame::CreateEnemy()
{
        video::IVideoDriver* driver = device->getVideoDriver();
	     scene::ISceneManager* smgr = device->getSceneManager();
       
//For debugging//
cout<<"Test 1"<< ENEMY_ID <<endl;
 enemy[ENEMY_ID].anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("./media/sydney.md2"));
cout<<"Test 2"<<endl;
enemy[ENEMY_ID].anms->setMaterialTexture(0, driver->getTexture("./media/sydney.bmp"));
cout<<"Test 3"<<endl;
//enemy[ENEMY_ID].anms->remove();
cout<<"Test 4"<<endl;
enemy[ENEMY_ID].anms->setPosition(camera->getPosition());

         ENEMY_ID++;


}
and I have two main structures for enemies and projectiles

Code: Select all

struct PointMass
	{
            scene::ISceneNode* node;
            float mass;
            core::vector3df velocity;
            core::vector3df acceleration;
            core::vector3df force;
            core::vector3df MapCollisionPoint;
            core::vector3df direction;
            //constructor
            PointMass()
            {
                velocity = core::vector3df(10,0,0);
            }


	} bullet[50];

	struct Enemy
	{
	    scene::IAnimatedMeshSceneNode* anms;

	     float mass;
	     scene::ISceneNode* node;
            core::vector3df velocity;
            core::vector3df acceleration;
            core::vector3df force;
            core::vector3df MapCollisionPoint;
	} enemy[5];
I get to "test 3" the SegFault :(

any ideas?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Suspicions:

The crash is actually on anms->setMaterialTexture() (because anms is 0), or on anms->setPosition().

It should crash on anms->setPosition(), since it anms will be dropped and deleted by anms->remove(). Don't try to use a scene node after you've called remove() on it (unless you called grab() first).

Are you absolutely sure that the crash is on anms->remove()? Don't rely on cout; the "Test 4" line may simply not have been flushed to the console before execution crashes in anms->setPosition(). endl is supposed to flush() the stream; then again, we supposedly went to the moon, but nobody seriously believes that.

You really should learn to use your debugger. It will tell you exactly what is happening, i.e. the call stack, the precise point of failure, and the values that caused the failure.

Start with the call stack. Find out how to get your debugger to show you that (it depends on your debugger or IDE) then examine it to see where the execution is at the point of the crash. I'm betting that it will be in anms->setPosition(), not anms->remove().
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
marrabld
Posts: 37
Joined: Wed Jul 11, 2007 9:16 am

Post by marrabld »

Thanks rgerborg and Eigen

I do need to get my head arround using my debugger. I use some times but I have trouble understanding some of its outputs. I use linux so the Gdb is all command line and not that user friendly.

That aside, If i don't call remove(); It doesn't crash. I can shoot all day, get my collision responder to tell me I hit the target, I just can't get it to destroy it.

I will however, take more time to learn how to use the gdb better.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Type "bt" to get a backtrace (aka call stack). This will tell you exactly which path the execution was on when it crashed.

There are plenty of friendly graphical front ends for gdb. Have you tried any?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
marrabld
Posts: 37
Joined: Wed Jul 11, 2007 9:16 am

Post by marrabld »

I have tried a GUI but I cant remember which one. Can you suggest one?

I am downloading Insight right now. i will take a break from the fun stuff now to improve my conseptual understanding.

but you migh be able to suggest how this is meant to be interepreted?

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7a526c0 (LWP 15522)]
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
isn't it supposed to tell me 'where' it stopped executing. Looks like even GDB doesn't even know...
Post Reply