View Full Version : SOIL returns segmentation fault

04-29-2016, 04:59 AM
Hi there

I've been moving some code from a windows platform to a ubuntu platform. Everything works fine on windows and most everything works well on ubuntu however I've hit a stumbling block and so far haven't been able to find a solution!

I've started including the SOIL library in my code now and when I call the command

cube->SetTexture("Create", SOIL_load_OGL_texture("./Textures/Create.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);

I am getting a segmentation fault which I'm sure is coming from the call to SOIL_load_OGL_texture. I know the rest of the code is operating fine (the previous test I ran was the same code but without using SOIL to load the texture and instead loading it manually (as it were)

Has anyone else experienced this issue when using SOIL under ubuntu 14.04?



Agent D
05-03-2016, 09:11 AM
I am getting a segmentation fault which I'm sure is coming from the call to SOIL_load_OGL_texture.

Do you just have a vague feeling or an actual stack trace that tells you where the segfault happens?

A segfault means that you are accessing virtual memory addresses that aren't mapped.

If it really happens inside SOIL_load_OGL_texture, it means that some global state is corrupted since you
obviously don't pass invalid pointers into that function.

Does SOIL have some initialization function that you didn't call?
From the name, I assume the function uses the OpenGL(R) API to create a texture object.Do you have a current context at the point where you call the function, i.e. is OpenGL(R) initialized at that point?
Does the segfault perhaps happen somewhere else? E.g. is "cube" a valid pointer or does it launch the program counter into hyperspace?

You should build a version of your program with debug symbols and use gdb/valgrind/$debugger, or at least printf debugging to
clarify that.

05-03-2016, 10:35 AM
Personally I'd recommend splitting SOIL_load_OGL_texture out to a separate line of code, and check if it's returning 0 or not. Cutesy code constructs to save lines of code may look nice but are often neither pragmatic nor helpful. A likely cause is that SOIL_load_OGL_texture is actually failing to load the texture, is returning 0, and you're not properly dealing with 0 values in your own "SetTexture".

As to why it's returning 0, one possible reason when porting from Windows to a Unix derived/inspired OS is case-sensitivity in the file system. Another possible cause is confusion in the paths leading to a bad working directory. In either case, the SOIL library is simply failing to find and open the file. At the very least this is something you can test yourself by trying to fopen the "./Textures/Create.bmp" file. This is also a useful test because it allows you to isolate the problem from any possible bugs in SOIL (which I doubt - the bugs are most likely in your own code). So try to reproduce it using fopen on the same path and see what happens; if it fails then you've an error due to case-sensitivity or a bad working directory, if it succeeds then SOIL itself (or your usage of SOIL) is more likely.

05-04-2016, 04:32 AM
I did of course do some debugging before I made my original post, and am aware that a segmentation fault is caused by memory. I did trace the error through to the SOIL_load_OGL_texture command. What I have failed to do is find where SOIL is installed on my linux box so that I can read the src files (I've only found the headers) to see if that shines some light on my problem.

I can confirm that the file opens perfectly when opened with 'fopen', so it is unlikely to be the file path or working directory causing the problem here.

I am wondering if there is some additional set up required for SOIL in a linux environment compared to Windows? Unfortunately, since my code now covers many different files it wouldn't be possible to post it here. Does anyone have a small piece of sample code that uses SOIL and the SOIL_load_OGL_texture command?


05-16-2016, 05:10 AM
Hi Guys,

Still no luck, anyone got any ideas?


05-16-2016, 08:38 AM
After many hours of faffing I have managed to install Code::Blocks and work out how to use it so I can attempt to trace the fault.

When I try to step into the line

SOIL_load_OGL_texture("home/ubuntu/Documents/OpenGL3/Open_GL_Basic_Engine/c2_4_DrawCubeTectureAdvanced/Textures/Crate.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);

The code returns a segmentation fault error and won't send me to the SOIL_load_OGL_texture function so I can try and trace the stack further.

I know the file is openable as I have tested using a simple fopen routine. I also know the rest of the code works and is able to load the texture if I don't use SOIL to perform the texture loading. However, I now wish to make SOIL work for me.

I'm really at a loss here and any help is appreciated


05-19-2016, 10:02 PM
Have you tried having the path run from the current directory you're in directly to the resource?

to just "c2_4_DrawCubeTextureAdvanced/textures/Crate.bmp"
Assuming c2_4_DrawCubeTextureAdvanced is the directory with the executable?