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

Author Topic: Segfault creating a fullscreen window on linux X11  (Read 1969 times)

0 Members and 1 Guest are viewing this topic.

dropout

  • Newbie
  • *
  • Posts: 5
    • View Profile
Segfault creating a fullscreen window on linux X11
« on: September 20, 2012, 05:47:08 pm »
Hi Dear SFML users!

I experienced a problem while creating a fullscreen styled window with SFML 2.0.
I cloned the repo from github compiled with clang++, and using a fresh install of Xubuntu 12.04 stable.

I have the following simple code:

#include "SFML/Window.hpp"

int main( int argc, char** argv ) {
     
    sf::ContextSettings settings;
    settings.antialiasingLevel = 2;
    settings.depthBits = 24;
    settings.stencilBits = 8;    
   
    sf::Window win;
    win.create( sf::VideoMode(1024,768), "Hello World", sf::Style::Fullscreen, settings );
   
    while ( win.isOpen() ) {
       
        sf::Event event;
        while ( win.pollEvent(event) ) {            
            if (event.type == sf::Event::Closed) {
                win.close();
            }
        }

        win.display( );
    }
   
    return 0;    
}
 

This application crashes (SEGFAULT) when trying to create a sf::Style::FullScreen window.
It disables my secondary monitor and changes my primary monitors resolution to the desired one specified in the application.
I need to recover my whole desktop after the crash.

Here is my callstack:

?? ()  
XCreateIC ()   
sf::priv::WindowImplX11::initialize (this=0xe71c00)    
sf::priv::WindowImplX11::WindowImplX11 (this=0xe71c00, mode={width = 1024, height = 768, bitsPerPixel = 32}, title=@0x7fffffffe538: {_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x8a8e18 \"Hello World\"}, static npos = <optimized out>}, style=8)     
sf::priv::WindowImpl::create (mode={width = 1024, height = 768, bitsPerPixel = 32}, title=@0x7fffffffe538: {_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x8a8e18 \"Hello World\"}, static npos = <optimized out>}, style=8)      
sf::Window::create (this=0x7fffffffe560, mode={width = 1024, height = 768, bitsPerPixel = 32}, title=@0x7fffffffe538: {_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x8a8e18 \"Hello World\"}, static npos = <optimized out>}, style=8, settings=@0x7fffffffe588: {depthBits = 24, stencilBits = 8, antialiasingLevel = 2, majorVersion = 2, minorVersion = 0})   
main (argc=1, argv=0x7fffffffe698)     
 

The problem arises when calling WindowImplX11.cpp's initialize function especially on line 476:
m_inputMethod = XOpenIM(m_display, NULL, NULL, NULL);
    m_inputContext = XCreateIC(m_inputMethod,
                                   XNClientWindow, m_window,
                                   XNFocusWindow,  m_window,
                                   XNInputStyle,   XIMPreeditNothing  | XIMStatusNothing,
                                   NULL);
 

Has anyone experienced the same?
Maybe it's not an SFML issue rather than a issue related to X11 or maybe a specific distro Xubuntu, but I'm not experienced in linux window management and couldn't figure it out myself.
If you have any ideas, please share with me :)

Thanks for your input in advance!


dropout

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Segfault creating a fullscreen window on linux X11
« Reply #1 on: September 20, 2012, 11:47:57 pm »
I couldn't rest on this problem so tried to find a solution, and it happens that a list of arguments XCreateIC takes must be ended with a casted NULL pointer.
https://github.com/dropout/SFML/compare/f5bca33eaa5d48ee613b07a1aea724794a8860ec...master
I made a pull request fixing it.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Segfault creating a fullscreen window on linux X11
« Reply #2 on: September 21, 2012, 12:01:48 am »
Does this cast seriously change anything??

And this piece of code is not specific to fullscreen, so this is even stranger...
Laurent Gomila - SFML developer

dropout

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Segfault creating a fullscreen window on linux X11
« Reply #3 on: September 21, 2012, 12:27:51 am »
Not sure about the cause...
Clang++ raised a warning which is eliminated by this cast, and now the full-screen mode works as expected.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Segfault creating a fullscreen window on linux X11
« Reply #4 on: September 21, 2012, 08:10:56 am »
Quote
Clang++ raised a warning which is eliminated by this cast
Yep, and it's more a bug of Clang. And of all the examples that I found, none is using such a cast (they all use NULL).

Are you on a 64-bit OS? Have you tried to remove the cast and make a complete rebuild?
Laurent Gomila - SFML developer

dropout

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Segfault creating a fullscreen window on linux X11
« Reply #5 on: September 21, 2012, 11:25:53 am »
Yes, I'm on 64Bit Xubuntu 12.04 fresh clean install, dependencies added through apt.
If I remove the cast it reintroduces the problem.
I've just made some additional testing with g++ 4.6, doesn't show a warning but still it crashes with the same problem.
It happens with with g++ 4.7 too.
I'm no C++ expert, rather a noob so I'm just using bare logic here, but it looks like the 64bit system has different sizes of NULL / 0 and maybe that is causing the segmentation fault. People had the same problem with execlp that made me think the problem is the same with XCreateIC.
Why it happens only in fullscreen mode, I have really no idea.
« Last Edit: September 21, 2012, 11:29:01 am by dropout »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Segfault creating a fullscreen window on linux X11
« Reply #6 on: September 21, 2012, 11:39:31 am »
Quote
it looks like the 64bit system has different sizes of NULL / 0 and maybe that is causing the segmentation fault
Yes, that's the only difference that can exist between your code and mine. The documentation is so bad that we can't be sure, but it seems that the XCreateIC function expects integers, not pointers. That's why it makes no sense.

Quote
People had the same problem with execlp that made me think the problem is the same with XCreateIC.
Can you post a link to what you found concerning execlp?

And thanks for your help :)
Laurent Gomila - SFML developer

dropout

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Segfault creating a fullscreen window on linux X11
« Reply #7 on: September 21, 2012, 12:41:55 pm »
Quote
Can you post a link to what you found concerning execlp?

The clang warning about missing sentinel in variadic function lead me to these pages:
http://stackoverflow.com/questions/12095865/spurious-missing-sentinel-in-function-call
http://blog.vucica.net/2009/08/fixing-warning-missing-sentinel-in-function-call.html

I'm glad that I could help, SFML is great, if not the greatest :) Amazing work, clean API.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Segfault creating a fullscreen window on linux X11
« Reply #8 on: September 21, 2012, 02:08:04 pm »
Thanks.

Even if it's still strange, and since the documentation is so crappy, I'll apply your modification if it makes things work.
Laurent Gomila - SFML developer

 

anything