You are not logged in.

#1 2016-11-21 15:49:00

mis
Member
Registered: 2016-03-16
Posts: 234

[Solved] [SFML] window.setIcon() causes segfault

A while ago I've  written a little SFML program and it worked fine. Today I compiled it again and got a segfault.
I figured out that the segfault happens when the setIcon() function of the RenderWindow class is used.

Same happens with this example: http://pastebin.com/8Yjnj3W3
compiled with: g++ -o sfml sfml.cpp -Wall -Werror -g -lsfml-graphics -lsfml-window -lsfml-system

$ LANG=C gdb -q ./sfml
Reading symbols from ./sfml...done.
(gdb) run
Starting program: /home/jim/sfml/sfml 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffecdb4700 (LWP 1461)]
[New Thread 0x7fffec3ae700 (LWP 1462)]
[New Thread 0x7fffebbad700 (LWP 1463)]
[New Thread 0x7fffeb3ac700 (LWP 1464)]
[New Thread 0x7fffeabab700 (LWP 1465)]
Success loading icon.png

Thread 1 "sfml" received signal SIGSEGV, Segmentation fault.
0x00007ffff6082c50 in _XData32 () from /usr/lib/libX11.so.6
(gdb) backtrace
#0  0x00007ffff6082c50 in _XData32 () from /usr/lib/libX11.so.6
#1  0x00007ffff605d683 in XChangeProperty () from /usr/lib/libX11.so.6
#2  0x00007ffff79752da in ?? () from /usr/lib/libsfml-window.so.2.4
#3  0x00000000004014ad in main () at sfml.cpp:21
(gdb) q
A debugging session is active.

        Inferior 1 [process 1455] will be killed.

Quit anyway? (y or n) y

So if I comment line 21 it works.

    // window.setIcon(256, 256, icon.getPixelsPtr());

I also tried different 256x256 png files, but no luck..
Under Windows the same code, compiled (same gcc options) with TDM-gcc and the precompiled SFML library, works as expected.

Is there anything wrong with the code or is this a bug?
Can anyone reproduce this?

Edit: The example is from the SFML wiki, just added the code for loading the image and setting the window icon.

Last edited by mis (2016-11-27 14:42:32)

Offline

#2 2016-11-21 18:31:30

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [Solved] [SFML] window.setIcon() causes segfault

And you're sure you got the size right? Using icon.getSize() instead of hardcoded values would make it more robust. Nothing else jumps out at me (but I've never used SFML).

Offline

#3 2016-11-21 18:59:23

mis
Member
Registered: 2016-03-16
Posts: 234

Re: [Solved] [SFML] window.setIcon() causes segfault

The hardcoded size is correct

std::cout << icon.getSize().x << " x " << icon.getSize().y << std::endl;

says 256 x 256

changed line 21

window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());

But same error... Seems like an upstream bug in SFML, I rebuild SFML with debug symbols and ran gdb again

(gdb) bt
#0  0x00007ffff6082c50 in _XData32 () from /usr/lib/libX11.so.6
#1  0x00007ffff605d683 in XChangeProperty () from /usr/lib/libX11.so.6
#2  0x00007ffff79752da in sf::priv::WindowImplX11::setIcon (this=0x7f39e0, width=256, height=256, 
    pixels=<optimized out>) at /build/sfml/src/SFML/src/SFML/Window/Unix/WindowImplX11.cpp:859                       
#3  0x00000000004014ad in main () at sfml.cpp:2

Looking at the SFML commits, there were some changes in WindowImplX11.cpp since the last realese. (including line 859)
Now it also makes sence to me that it works on Windows. (SFML/Window/Unix/WindowImplX11.cpp)

Edit: I think I'll report it upstream.

Edit: Will be fixed in the next SFML release 2.4.2

Last edited by mis (2016-11-27 14:44:26)

Offline

Board footer

Powered by FluxBB