SFML community forums

Help => General => Topic started by: strongdrink on September 11, 2011, 04:02:59 am

Title: SFML2 SegFaults on Clear
Post 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
Code: [Select]

#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
Title: Re: SFML2 SegFaults on Clear
Post by: Haikarainen on September 11, 2011, 06:14:29 am
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?
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 11, 2011, 02:12:51 pm
Ok, here is my gdb output.

Code: [Select]

(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)
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 13, 2011, 12:55:44 am
bump
Title: SFML2 SegFaults on Clear
Post by: Haikarainen on September 13, 2011, 01:17:18 am
Have you tried window.Clear(sf::Color(254,254,254,254)); ?
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 13, 2011, 02:36:32 am
No dice. Still segments
Title: SFML2 SegFaults on Clear
Post by: coolhome on September 13, 2011, 03:24:32 am
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++
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 13, 2011, 04:48:20 am
Still no dice :S Laurent!! :P
Title: SFML2 SegFaults on Clear
Post by: Haikarainen on September 13, 2011, 04:55:53 am
Try

Code: [Select]
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:

Code: [Select]
std::cout << window;

and tell us what it says
Title: SFML2 SegFaults on Clear
Post by: Haikarainen on September 13, 2011, 05:00:54 am
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
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 13, 2011, 02:21:14 pm
It just gives a differant hex address every time

Code: [Select]

$ 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
Title: SFML2 SegFaults on Clear
Post by: Haikarainen on September 13, 2011, 04:14:05 pm
Quote from: "strongdrink"
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.
Title: SFML2 SegFaults on Clear
Post by: Laurent on September 13, 2011, 09:48:11 pm
Have you tried to upgrade/change your graphics drivers? Does glxgear run without any problem?
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 18, 2011, 11:19:07 pm
Yes, glxgears runs fine.
Title: SFML2 SegFaults on Clear
Post by: strongdrink on September 19, 2011, 12:04:40 am
Ok, I compiled from source and its all good...

KTHXBYE!