Segmentation Fault? What's that mean?
Posted: Mon Mar 20, 2006 10:58 pm
I'm getting an error from my program called "segmentation fault". I'm very new to C++ and Irrlicht, so I don't know what that means, or if it's coming from the engine, or from something else in my program, or what. I have narrowed down the cause to around my tcySprite class, but I'm not sure exactly where it's happening.
Most of the code I'm using consists of alterations to the 2D graphics demo included with Irrlicht. I have added one class:
... and one function:
The class is supposed to be an animated sprite, with an array of rectangles referring to regions of a texture to use as animation frames. It has a function to draw itself, which I have had problems with before, but if it acts up again I'll make a separate thread for it. For now, I have no way to test it.
The MakeSprite function seems to be what's causing the problem. Sticking "tcySprite* SpriteName" in my program isn't giving me any problems, but setting it equal to what MakeSprite returns gives me the segmentation fault error.
Here's how I'm using it:
And the program's output when I run it:
(The four "libGL warning" lines are generated every time I run the program, fault or not, but seem to pose no problem. I don't know what those mean, either.)
As you can see above, I'm using Linux 2.6, along with OpenGL. In case it somehow matters, I'm editing my code in Kdevelop, and using whatever default options it has to compile. I would try the debugger, but I have no idea how it works.
So there it is. My overcomplicated explanation of a problem which is probably as simple to fix as adding a comma somewhere. Again, I'm very new to C++, and this is the first project I've worked on using Irrlicht, so please make your explanations as soft and round as possible. That said, any kind of help is appreciated, and Technocracy's credits has plenty of empty space in the "Special Thanks" section.
Thanks in advance.
Most of the code I'm using consists of alterations to the 2D graphics demo included with Irrlicht. I have added one class:
Code: Select all
class tcySprite{
public:
IVideoDriver* SDriver;
ITexture* ImageSource;
rect<s32> frame[];
int FrameCount;
void DrawSprite(int XIn, int YIn, int FrameIn){
SDriver->draw2DImage(ImageSource, position2d<s32>(XIn, YIn),
frame[FrameIn], 0,
SColor(255,255,255,255), true);
}
};Code: Select all
tcySprite* MakeSprite(IVideoDriver* SDriverIn, ITexture* ImageSourceIn, int FrameWidthIn, int FrameHeightIn, int RowIn, int FrameCountIn){
tcySprite* SpriteOut;
SpriteOut -> SDriver = SDriverIn;
SpriteOut -> ImageSource = ImageSourceIn;
for (int i = 0; i < FrameCountIn; i += 1){
SpriteOut -> frame[i] = rect<s32>((FrameWidthIn*i), (FrameHeightIn*RowIn), (FrameWidthIn*i)+(FrameWidthIn-1), (FrameHeightIn*RowIn)+(FrameHeightIn-1));
}
return SpriteOut;
}The MakeSprite function seems to be what's causing the problem. Sticking "tcySprite* SpriteName" in my program isn't giving me any problems, but setting it equal to what MakeSprite returns gives me the segmentation fault error.
Here's how I'm using it:
Code: Select all
ITexture* TextureShira = driver->getTexture("./media/shira.png");
//Allows the program to continue:
tcySprite* SpriteShira01;
//Generates a segmentation fault:
tcySprite* SpriteShira02 = MakeSprite(driver, TextureShira, 32, 64, 0, 12);Code: Select all
Please select the driver you want for this example:
(a) Direct3D 9.0c
(b) Direct3D 8.1
(c) OpenGL 1.5
(d) Software Renderer
(e) Apfelbaum Software Renderer
(f) NullDevice
(otherKey) exit
Automatically chosen: OpenGL [b](I told it to do this.)[/b]
Irrlicht Engine version 0.14.0
Linux Linux 2.6.12-10-386 #1 Sat Mar 11 16:13:17 UTC 2006
Creating X window...
libGL warning: 3D driver claims to not support visual 0x24
libGL warning: 3D driver claims to not support visual 0x28
libGL warning: 3D driver claims to not support visual 0x2c
libGL warning: 3D driver claims to not support visual 0x30
Using renderer: OpenGL 1.5
OpenGL driver version is 1.2 or better.
Multittexturing active.
Loaded texture: #DefaultFont
Loaded texture: ./media/shira.png
Segmentation fault
As you can see above, I'm using Linux 2.6, along with OpenGL. In case it somehow matters, I'm editing my code in Kdevelop, and using whatever default options it has to compile. I would try the debugger, but I have no idea how it works.
So there it is. My overcomplicated explanation of a problem which is probably as simple to fix as adding a comma somewhere. Again, I'm very new to C++, and this is the first project I've worked on using Irrlicht, so please make your explanations as soft and round as possible. That said, any kind of help is appreciated, and Technocracy's credits has plenty of empty space in the "Special Thanks" section.
Thanks in advance.