SFML community forums

Help => General => Topic started by: atp on October 27, 2013, 05:17:13 am

Title: Segmentation fault while trying tutorial
Post by: atp on October 27, 2013, 05:17:13 am
The tutorial at http://www.sfml-dev.org/tutorials/2.1/start-linux.php gives a segmentation fault, and I think it is caused by these two lines:

window.clear();
window.draw(shape);
 

Is this somehow related to the graphics driver (I'm using bumblebee for nvidia optimus support)?
Title: Re: Segmentation fault while trying tutorial
Post by: Nexus on October 27, 2013, 11:08:33 am
Why do you think it's because of these two lines? Can you show a minimal complete code that still reproduces the problem (remove everything that doesn't trigger the segmentation fault).

How did you setup and link everything? A lot of such errors are related to wrong configurations.
Title: Re: Segmentation fault while trying tutorial
Post by: atp on October 27, 2013, 04:20:22 pm
Why do you think it's because of these two lines? Can you show a minimal complete code that still reproduces the problem (remove everything that doesn't trigger the segmentation fault).

When I remove window.clear(), the window is shown and no error message appears. So, it is caused by that line.

How did you setup and link everything? A lot of such errors are related to wrong configurations.

By using the same lines as in the tutorial:
g++ -c test.cpp
g++ test.o -o sfml-app -L/home/andreas/games_ws/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
Title: Re: Segmentation fault while trying tutorial
Post by: FRex on October 27, 2013, 04:53:21 pm
Try to replace clear with what clear really does and see which line crashes(if any still does).
if(window.setActive())
{
glClearColor(0.f,0.f,0.f,1.f);
glClear(GL_COLOR_BUFFER_BIT);
}
 
should work but you need to link opengl yourself.
You can also try running with debug SFML with some IDE(or just raw gdb) and seeing where in SFML it crashes.
Title: Re: Segmentation fault while trying tutorial
Post by: atp on October 28, 2013, 12:24:44 am
The code you have posted works fine. So, why does window.clear() not work?
Title: Re: Segmentation fault while trying tutorial
Post by: FRex on October 28, 2013, 12:32:39 am
It should.
All additional work window does when clearing is run that: https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/GLCheck.cpp#L37 after each gl function where file is __FILE__ and line is __LINE__ . You can try that too(copy that entire one function to your file, in SFML it's hidden-ish) but it really should work if everything else does and same gl does.
So now it's :
if(window.setActive())
{
glClearColor(0.f,0.f,0.f,1.f);
glCheckError(__FILE__,__LINE__);
glClear(GL_COLOR_BUFFER_BIT);
glCheckError(__FILE__,__LINE__);
}
(SFML actually uses macro to conditionally compile this in but it's same code in same order as it).