-
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)?
-
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.
-
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
-
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.
-
The code you have posted works fine. So, why does window.clear() not work?
-
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).