Segmentation fault when loading a mesh
Segmentation fault when loading a mesh
ok here is the code:
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
int main() {
IrrlichtDevice* device;
createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
if (!device) return 1;
IVideoDriver* driver;
device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IMesh* mesh = smgr->getMesh("sydney.md2");
IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
smgr ->addCameraSceneNode(0,vector3df(0,30,-40),vector3df(0,5,0));
while (device->run()) {
driver->beginScene(true,true,SColor(255,255,255,255));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
this was built with code::blocks on linux mint cinnamon, and when run it says: Segmentation fault (core dumped).
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
int main() {
IrrlichtDevice* device;
createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
if (!device) return 1;
IVideoDriver* driver;
device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IMesh* mesh = smgr->getMesh("sydney.md2");
IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
smgr ->addCameraSceneNode(0,vector3df(0,30,-40),vector3df(0,5,0));
while (device->run()) {
driver->beginScene(true,true,SColor(255,255,255,255));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
this was built with code::blocks on linux mint cinnamon, and when run it says: Segmentation fault (core dumped).
Re: Segmentation fault when loading a mesh
Without running the code I see that this won't work:
Do it like this:
Code: Select all
IrrlichtDevice* device;
createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
Code: Select all
IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
It'll only take a minute or two to debug this code...
Re: Segmentation fault when loading a mesh
i just did this but it wont work for some reason.
Now it says Aborted(core dumped)
could this problem be caused by my distrobution of linux
(im using mint but i got the irrlicht for ubuntu)
Now it says Aborted(core dumped)
could this problem be caused by my distrobution of linux
(im using mint but i got the irrlicht for ubuntu)
Re: Segmentation fault when loading a mesh
Dude, do you know what pointers are? You are declaring pointers but never assigning them, hence the crash.
the failure is here, guess why.
Unless you know what happens here, you can't really use Irrlicht, or else you will be finding yourself inmerse in continuous, and elemental errors, and you won't know why. Keep studying.
the failure is here, guess why.
Code: Select all
driver->beginScene(true,true,SColor(255,255,255,255));
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Segmentation fault when loading a mesh
yes i do.
i use to use the Alegro engine for 2d graphics in c++
when loading a bitmaps i would get this error very often.
i wld really like to know why exactly, but i think it is to do with the program loading up too much data, and getting rid of it
in order to avoid a crash.
i use to use the Alegro engine for 2d graphics in c++
when loading a bitmaps i would get this error very often.
i wld really like to know why exactly, but i think it is to do with the program loading up too much data, and getting rid of it
in order to avoid a crash.
Re: Segmentation fault when loading a mesh
I wonder why... well, that's not it, a program may load tons of memory and free it many times and won't crash. It is more elemental than that. Take a look at the pointers you are declaring. There is something missing that is very important to pointers, to any variable actually, but for pointers this lack leads to program errors and core dumpings.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Segmentation fault when loading a mesh
Code: Select all
IVideoDriver* driver;
device->getVideoDriver();
Re: Segmentation fault when loading a mesh
well, pointers point to any, say variable, by being equal to that variables address in the computers data storage.
So is it because the driver isnt being assigned anything to point to???
So is it because the driver isnt being assigned anything to point to???
Re: Segmentation fault when loading a mesh
and also the first line of eejin's copied code is declaring the driver, creating it.
but i dont understand why then the device is '"getting" it again?
but i dont understand why then the device is '"getting" it again?
Re: Segmentation fault when loading a mesh
It is from your post. You don't give driver a correct value. Thus you should give it the value that getVideoDriver returns.
Now driver points to the videodriver. Now beginscene can be called with the correct driver .
Code: Select all
IVideoDriver* driver = device->getVideoDriver();
Re: Segmentation fault when loading a mesh
im gonna try it.
4 some reason when i looked in my book, my code was right.
maybe because the book is for irrlicht 1.7.2.
i case u wanna take a look it's called irrlicht 1.7.2 a begginers guide
4 some reason when i looked in my book, my code was right.
maybe because the book is for irrlicht 1.7.2.
i case u wanna take a look it's called irrlicht 1.7.2 a begginers guide
Last edited by axtyax on Mon Apr 01, 2013 3:38 pm, edited 1 time in total.
Re: Segmentation fault when loading a mesh
wait it still says aborted(core dumped)????
Re: Segmentation fault when loading a mesh
i think that this is to do with my code not being able to access sydney.md2 and is giving me the error.
i know this because i used to use allegro for 2d graphics and this was the most common problem,
the program wouldnt be able to load the bitmaps.
i know this because i used to use allegro for 2d graphics and this was the most common problem,
the program wouldnt be able to load the bitmaps.
Re: Segmentation fault when loading a mesh
I looked over it but shouldn't this:
Be this:
Code: Select all
IrrlichtDevice* device;
createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
Code: Select all
IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2d<u32>(640,480),16, false,false,false,0);
Re: Segmentation fault when loading a mesh
Yes, pointers are initialized using an assignation, hence, anything like
IVideoDriver* driver;
device->getVideoDriver();
is not correct because driver is never assigned.
IVideoDriver* driver = device->getVideoDriver();
And it is the same as with all the pointers.
Now, Not being able to load the sydney.md2 model is a more reasonable error. You probably haven't suplied it the right path. But Irrlicht returns 0 when it is unable to load a mesh, so you should check that the returned value of the loading method isn't 0; in that case, keep going on, else, you won't see a thing, but the program won't crash.
Try executing your program within the debugger, it will tell you the exact line the program is failing, and what the error is. a Segmentation fault and core dumping is due mainly to bad pointers usage. This works with Allegro too.
IVideoDriver* driver;
device->getVideoDriver();
is not correct because driver is never assigned.
IVideoDriver* driver = device->getVideoDriver();
And it is the same as with all the pointers.
Now, Not being able to load the sydney.md2 model is a more reasonable error. You probably haven't suplied it the right path. But Irrlicht returns 0 when it is unable to load a mesh, so you should check that the returned value of the loading method isn't 0; in that case, keep going on, else, you won't see a thing, but the program won't crash.
Try executing your program within the debugger, it will tell you the exact line the program is failing, and what the error is. a Segmentation fault and core dumping is due mainly to bad pointers usage. This works with Allegro too.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt