SFML community forums
Help => General => Topic started by: strongdrink on September 11, 2011, 04:02:59 am
-
Greetings
I'm having an issue with running SFML apps.
They compile with no problem, but when I run them, it segFaults on window.Clear();
main.cpp
#include <SFML/Graphics.hpp>
int main() {
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Start the game loop
while (window.IsOpened()) {
// Process events
sf::Event event;
while (window.PollEvent(event)) {
// Close window : exit
if (event.Type == sf::Event::Closed) {
window.Close();
}
}
// Clear screen
window.Clear();
// Update the window
window.Display();
}
return EXIT_SUCCESS;
}
and to compile i use
g++ -g -o main main.cpp -lGL -lGLU -lsfml-system -lsfml-window -lsfml-graphics && ./main
-
This is weird, remember having the same problem on 1.6 running linux debian 5 , dont remember any solution though.
Can you get the stack trace with sfml-d debugging symbols as well?
-
Ok, here is my gdb output.
(gdb) run
Starting program: /home/elijah/cplusplus/test/main
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff728b69c in sf::RenderTarget::Clear(sf::Color const&) () from /usr/lib/libsfml-graphics.so.2
(gdb) bt
#0 0x00007ffff728b69c in sf::RenderTarget::Clear(sf::Color const&) () from /usr/lib/libsfml-graphics.so.2
#1 0x0000000000400e02 in main () at main.cpp:26
(gdb)
-
bump
-
Have you tried window.Clear(sf::Color(254,254,254,254)); ?
-
No dice. Still segments
-
Just taking a shot in the dark here but what if you tried.
g++ -g -o main main.cpp -lGL -lGLU -lsfml-graphics -lsfml-window -lsfml-system && ./main
I think the order of the linking matters.
p.s. I'm a noob with G++
-
Still no dice :S Laurent!! :P
-
Try
sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(800,600,32), "bleh");
instead, and make sure the rest of the code handles window like a pointer. Then do:
std::cout << window;
and tell us what it says
-
Btw, other known errors for this:
linking releaselibs to debug target, or vice versa
dependency problems - try rebuilding sfml all from scratch
Example: http://www.sfml-dev.org/forum/viewtopic.php?p=34143&sid=58f2a02ab20abf78b56b173439f4db23
-
It just gives a differant hex address every time
$ g++ -g -o main main.cpp -lGL -lGLU -lsfml-graphics -lsfml-window -lsfml-system && ./main
0x104ab30
$ g++ -g -o main main.cpp -lGL -lGLU -lsfml-graphics -lsfml-window -lsfml-system && ./main
0x24cbb30
$ g++ -g -o main main.cpp -lGL -lGLU -lsfml-graphics -lsfml-window -lsfml-system && ./main
0x176eb30
$ g++ -g -o main main.cpp -lGL -lGLU -lsfml-graphics -lsfml-window -lsfml-system && ./main
0x838b30
-
It just gives a differant hex address every time
Allright, how about the second thing i posted about? My bat-sense tells me its that.
Either you link the wrong libraries to the wrong target (debug to release or vice versa)
OR
You mix library files, like link 2.0 but have 1.6 headers, or vice versa.
My tip: Remove ALL sfml files, download new files, try it.
-
Have you tried to upgrade/change your graphics drivers? Does glxgear run without any problem?
-
Yes, glxgears runs fine.
-
Ok, I compiled from source and its all good...
KTHXBYE!