Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Segmentation fault while trying tutorial  (Read 1866 times)

0 Members and 1 Guest are viewing this topic.

atp

  • Newbie
  • *
  • Posts: 3
    • View Profile
Segmentation fault while trying tutorial
« 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)?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Segmentation fault while trying tutorial
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

atp

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Segmentation fault while trying tutorial
« Reply #2 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
« Last Edit: October 27, 2013, 04:23:07 pm by atp »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Segmentation fault while trying tutorial
« Reply #3 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.
Back to C++ gamedev with SFML in May 2023

atp

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Segmentation fault while trying tutorial
« Reply #4 on: October 28, 2013, 12:24:44 am »
The code you have posted works fine. So, why does window.clear() not work?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Segmentation fault while trying tutorial
« Reply #5 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).
« Last Edit: October 28, 2013, 12:38:41 am by FRex »
Back to C++ gamedev with SFML in May 2023

 

anything