Run time error? WTF

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.
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Run time error? WTF

Post by belva1234 »

Hy i've a problem when i use the SchootBloock function the program crasch:

Code: Select all

void SchootBlocks(){
 scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
 
        //da modificare la texture blocco in base all blocco che si e selezionato
     IAnimatedMesh *blocco=smgr->getMesh("../../media/blocco.3ds");
     IAnimatedMeshSceneNode *blocconode=smgr->addAnimatedMeshSceneNode(blocco);
    blocconode->setMaterialFlag(video::EMF_LIGHTING,false);
                core::line3d<f32> ray;
                ray.start = cam->getPosition();
                ray.end = ray.start + (cam->getTarget() - ray.start).normalize() * 1000.0f;
                core::vector3df intersection;
                core::triangle3df hitTriangle;
                scene::ISceneNode * selectedSceneNode =collMan->getSceneNodeAndCollisionPointFromRay(ray,intersection,hitTriangle ,-1, 0);
                        blocconode->setPosition(intersection);
        mapSelector->drop();
}
the compile schow a run time error :

Code: Select all

scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

A runtime error can't be on compile (that would be a compile error). What kind of error do you have? If you get an error always post it's error-message.

If it's a runtime crash then most likely smgr is not correctly initialized at that point.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

it isn't an error : when i lunch the program and the function schoot blocks start the program crasch and the visual c++ schow the line where the program crasch

Code: Select all

 scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

Yeah, already told you the most likely reason - smgr not pointing to the correct place in memory. Can't tell more with just seeing this part of the code.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

I've no idea pleas read the pm :(
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

Brr... just post code in the forum, don't PM such stuff please.

Your problem is basically that you have a global and a local version of smgr which have the same name but nothing to do with each other otherwise (aka they are _not_ the same space in memory which is the main reason for variables - variables are names to make it easy for you to refer to a part of the memory). Your smgr in main() overrides the global smgr (when names do clash the compiler always uses the one declared in the most inner scope). So that smgr in your main() is only valid inside the scope of main and you do assign the irrlicht scenemanager only to that variable. While in SchootBlocks you use the global smgr instead which is never initialized anywhere, so it just points to a random place in memory.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

Ok i'v understend but how do I replace smgr in the schootblock function
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

You have several choices:
1. Use only the global (ugly, but works for such small programs)
2. Remove the global and pass smgr as parameter to every function which needs it.
3. Remove the global and local smgr and use classes instead and put it into the same class where your functions are in.
Pass the smgr to the class and allow access to it from other classes on need. That's the object oriented way.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

Since I can't understand can you try to adapt the function schootblock with the 2 option that you' ve said
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

What do you not understand? What a global is? How to remove a variable? How to pass a variable as function parameter? How to put variables in a class?

There is no point in coding that for you unless you understand what's going. Otherwise you will just be back an hour later with your next problem and expect someone to spell it out for you.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

I don't understand How to pass a variable as function parameter
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

Well, it's a pointer. There's a million examples in Irrlicht (basically nearly every function):

Code: Select all

 
void SchootBlocks(irr::scene::ISceneManager* sceneManager )
{
// your stuff
}
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

Ok I solved the problem but when I press the left button i don' t see any block, but the compiler says that it was generated
Non funziona merda...
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Run time error? WTF

Post by CuteAlien »

Please no cross-posting of problems. We just delete cross-posted threads. And the compiler can only check your code for syntax - it has no idea what the code should do. If your program works or not depends on you coding skills and not the compiler.

Maybe it's outside the camera view. Or any other problem. Why do you ask for every step in your program for help in the forum? Start figuring out things for yourself. If this is still too hard then write simpler programs first - learning c++ and 3D programming at the same time is way too hard. Do simpler programs first until you know c++ good enough.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
belva1234
Posts: 44
Joined: Sat Apr 07, 2012 2:00 pm

Re: Run time error? WTF

Post by belva1234 »

I understand the C + + and irrlicht a little less but my code would place the 'object where the camera and map collidono.Per this I have no idea why the code does not go right and you can check yourself over ...
Non funziona merda...
Post Reply