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

Author Topic: Create RenderWindow on Linux failing with a segmentation fault.  (Read 8679 times)

0 Members and 1 Guest are viewing this topic.

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Hello, I'm trying to port my stuff from Windows to Linux but I've run into a problem. Whenever I create a render window (haven't tried with a normal window but I assume it will be the same) mono crashes with a segmentation fault.

I'm using CSFML and SFML 2.4 compiled on linux using this guide: https://blaxpirit.com/blog/12/build-sfml-and-csfml-on-linux.html

The line of code which crashes is:

sfRenderWindow_create (new VideoMode (), "test", Styles.Default, ref TestSettings);

Any ideas?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #1 on: August 04, 2017, 11:51:14 pm »
sfRenderWindow_create (new VideoMode (), "test", Styles.Default, ref TestSettings);
Is this some example code? Because the VideoMode shouldn't be empty.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #2 on: August 04, 2017, 11:56:59 pm »
It was an example yeah, actual is non-empty and still produces the same result.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #3 on: August 05, 2017, 12:39:24 pm »
Are you calling sfRenderWindow_create yourself?

Can you provide an example of this behavior?

I just pulled and built CSFML and SFML.NET, and the following program builds and runs without any errors (Arch Linux, x64):

using SFML.Graphics;
using SFML.Window;

static class Program
{
    public static void Main(string[] args)
    {
        var rw = new RenderWindow(new VideoMode(800, 600, 24), "test", Styles.Default);

        rw.Clear();
        rw.Display();
    }
}
 

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #4 on: August 07, 2017, 07:47:44 pm »
Are you calling sfRenderWindow_create yourself?

Can you provide an example of this behavior?

I just pulled and built CSFML and SFML.NET, and the following program builds and runs without any errors (Arch Linux, x64):

using SFML.Graphics;
using SFML.Window;

static class Program
{
    public static void Main(string[] args)
    {
        var rw = new RenderWindow(new VideoMode(800, 600, 24), "test", Styles.Default);

        rw.Clear();
        rw.Display();
    }
}
 

Which version of CSFML and SFML did you compile on Linux? Also can you attach the libraries you compiled and a compiled version of your code?
« Last Edit: August 07, 2017, 09:33:51 pm by Cryru »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #5 on: August 07, 2017, 10:19:02 pm »
I have SFML 2.4.2 installed.

I compiled CSFML and SFML.NET master branches.

I added a bit more code to make it easier to see the results of running the test.

(Had to upload to my dropbox - too large for the forums)
CSFML libs
SFML.NET libs
test program

Need mono installed for mcs if you want to make the test program yourself.

Also, should mention: I had to make symlinks for the csfml libs in the format: "libcsfml-<module>-2.so" myself, as that's what the DllImports are looking for (Windows style, instead of the Linux style of libcsfml-<module>.so.<version>).

Depending what distro you're on, the libraries I uploaded may not work, fyi.
« Last Edit: August 07, 2017, 10:31:11 pm by dabbertorres »

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #6 on: August 08, 2017, 12:23:09 am »
I have SFML 2.4.2 installed.

I compiled CSFML and SFML.NET master branches.

I added a bit more code to make it easier to see the results of running the test.

(Had to upload to my dropbox - too large for the forums)
CSFML libs
SFML.NET libs
test program

Need mono installed for mcs if you want to make the test program yourself.

Also, should mention: I had to make symlinks for the csfml libs in the format: "libcsfml-<module>-2.so" myself, as that's what the DllImports are looking for (Windows style, instead of the Linux style of libcsfml-<module>.so.<version>).

Depending what distro you're on, the libraries I uploaded may not work, fyi.

Using your code + your libraries and your code + my libraries yields the same result. I guess something is wrong with my Linux/Machine?
« Last Edit: August 08, 2017, 06:43:51 am by Cryru »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #7 on: August 08, 2017, 07:09:15 pm »
I have SFML from the Arch Linux repos installed, which is why I didn't need to build it myself.

I'm not surprised they didn't work.

Which C/C++ compiler are you using? Which distro? Which versions?

Did you build SFML master, or a specific version?

You might want to start over from the top - wipe all traces of any SFML from your system, clone fresh copies, and rebuild.
Document each step you make. It's likely just a config issue - which will be easier to find this way.

For what it's worth, these are the steps I would take:
(click to show/hide)
« Last Edit: August 08, 2017, 07:33:04 pm by dabbertorres »

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #8 on: August 09, 2017, 06:59:30 am »
Rebuilding everything didn't fix it. Im using Mint 18 and Ubuntu 16 if that matters.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #9 on: August 09, 2017, 10:24:51 pm »
I'm going to spin up a fresh Ubuntu image, build the master branches of SFML, CSFML, and SFML.NET, and see if I can reproduce (yay for containers).

Alright, so, I am able to reproduce the segfault on a fresh Ubuntu 16.04. Interesting.

Container images if interested:
https://hub.docker.com/r/dabbertorres/sfml.net-ubuntu-16.04/

I'll try and debug it and see where that gets me.
« Last Edit: August 10, 2017, 12:57:31 am by dabbertorres »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #10 on: August 10, 2017, 10:45:06 pm »
Oh, so I happened to figure it out (no more segfaulting).

Do you happen to have g++ 5.x installed, and used that to compile SFML and CSFML?

There was a bug affecting a few versions of the g++ compiler that causes this issue (it affects SFML and CSFML programs as well, that's how I found it).

There is a patch to apply to SFML's CMakeLists.txt that, after rebuilding SFML, fixes the issue.

First, you'll need to wipe and rebuild SFML, and then you have two options: get a newer compiler (Best option in my mind), or apply the linked patch after cloning.

Then, you should be back in business!

Cryru

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #11 on: August 11, 2017, 08:00:18 am »
That worked, amazing.
« Last Edit: August 11, 2017, 08:13:01 am by Cryru »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Create RenderWindow on Linux failing with a segmentation fault.
« Reply #12 on: August 11, 2017, 08:17:18 am »
One of those once in a lifetime cases where you could blame it on the compiler, haha.

Glad it's fixed!

 

anything