SFML community forums

Bindings - other languages => DotNet => Topic started by: Cryru on August 04, 2017, 09:34:25 am

Title: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru on August 04, 2017, 09:34:25 am
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?
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: eXpl0it3r 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.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru on August 04, 2017, 11:56:59 pm
It was an example yeah, actual is non-empty and still produces the same result.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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();
    }
}
 
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru 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?
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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 (https://www.dropbox.com/s/ovpgilfehwvbxdw/csfmllibs.tar.gz?dl=1)
SFML.NET libs (https://www.dropbox.com/s/ep4jtg7hx2t6740/sfmlnetlibs.tar.gz?dl=1)
test program (https://www.dropbox.com/s/8k0s7zo65saeqik/testproject.tar.gz?dl=1)

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.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru 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 (https://www.dropbox.com/s/ovpgilfehwvbxdw/csfmllibs.tar.gz?dl=1)
SFML.NET libs (https://www.dropbox.com/s/ep4jtg7hx2t6740/sfmlnetlibs.tar.gz?dl=1)
test program (https://www.dropbox.com/s/8k0s7zo65saeqik/testproject.tar.gz?dl=1)

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?
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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)
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru on August 09, 2017, 06:59:30 am
Rebuilding everything didn't fix it. Im using Mint 18 and Ubuntu 16 if that matters.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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 (https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899) 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 (https://gitlab.peach-bun.com/pinion/SFML/commit/3383b4a472f0bd16a8161fb8760cd3e6333f1782.patch) 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!
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: Cryru on August 11, 2017, 08:00:18 am
That worked, amazing.
Title: Re: Create RenderWindow on Linux failing with a segmentation fault.
Post by: dabbertorres 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!