ofImage crashes with "Segmentation Fault" error on Ubuntu

#1

Hi everyone

I have a program running on Ubuntu that is showing multiple images.
I have a strange problem with ofImage. When it reaches a specific image, it crashes my program with the following error:

Segmentation Fault (core dumped)

I have created a simple program which does nothing but loading the image. It doesn’t even draw the image, and with this specific image, it always crashes. so the code is really simple (it’s in my setup function):

ofImage img;
img.loadImage("images/test.jpg");

The image is about 7mb and it opens fine with ubuntu’s image viewer. I have also tested the code with images as big as 30mb’s and it works fine, so the size is not the problem.

Since my program is supposed to load images provided by a third party, changing the images would not be an option.
Can someone tell me what I can do to fix this?

I tested the same image in openframeworks on Windows7 and it works. So the problem happens only in Ubuntu.

Thanks in advance

EDIT: I cropped the faulty image just a little bit and now it loads without crashing my program. Since I have been able to load much bigger images with bigger dimensions, I’m not sure how this tiny cropping has that effect. In any case, since I don’t have access to the images passed to the program at runtime, even if the program can’t load the image, it would be nice to at least prevent the program from crashing. I used try/catch blocks but didn’t help. any ideas?

Img.load Segmentation fault (core dumped)
#2

I can’t seem to find any solution for this problem. I’ve even tried using ofPixels and textures instead.
I also tried reading the image with ofFile and ofBuffer, but after loading the buffer into image with ofLoadImage, it Still crashes every time.

I used gdb to run the program in the command line and here’s the output when it crashes:

Program received signal SIGSEGV, Segmentation fault.
0x000000000048c3f9 in std::swap<unsigned char> (__a=@0x7fffeae90fff: 0 '\000', 
    __b=@0x7fffeae91001: <error reading variable>)
    at /usr/include/c++/4.8/bits/move.h:176
176          __a = _GLIBCXX_MOVE(__b);

here’s the output after running bt :

> #0  0x000000000048c62e in std::swap<unsigned char> (__a=@0x7fffeb6d6000: 127 '\177', __b=@0x7fffeb6d6002: 76 'L') at /usr/include/c++/4.8/bits/move.h:176
> #1  0x000000000048a6a0 in ofPixels_<unsigned char>::swapRgb (this=0xafdfd0) at ../../../libs/openFrameworks/graphics/ofPixels.cpp:421
> #2  0x0000000000487a3f in putBmpIntoPixels<unsigned char> (bmp=0xafe0e0, pix=..., swapForLittleEndian=true) at ../../../libs/openFrameworks/graphics/ofImage.cpp:219
> #3  0x0000000000483286 in loadImage<unsigned char> (pix=..., fileName=...) at ../../../libs/openFrameworks/graphics/ofImage.cpp:264
> #4  0x0000000000482aea in ofLoadImage (pix=..., fileName=...) at ../../../libs/openFrameworks/graphics/ofImage.cpp:323
> #5  0x0000000000486c3e in ofImage_<unsigned char>::load (this=0xafdfb0, fileName=...) at ../../../libs/openFrameworks/graphics/ofImage.cpp:688
> #6  0x0000000000486f3b in ofImage_<unsigned char>::loadImage (this=0xafdfb0, fileName=...) at ../../../libs/openFrameworks/graphics/ofImage.cpp:707
> #7  0x0000000000415be8 in ofApp::setup (this=0xaff820) at src/ofApp.cpp:7
> #8  0x00000000004161d3 in ofBaseApp::setup (this=0xaff820, args=...) at ../../../libs/openFrameworks/app/ofBaseApp.h:41
> #9  0x0000000000428fde in Poco::PriorityDelegate<ofBaseApp, ofEventArgs, false>::notify (this=0xafe2c0, sender=0x0, arguments=...) at ../../../libs/poco/include/Poco/PriorityDelegate.h:168
> #10 0x000000000043024f in Poco::PriorityStrategy<ofEventArgs, Poco::AbstractPriorityDelegate<ofEventArgs> >::notify (this=0x7fffffffdb30, sender=0x0, arguments=...)
>     at ../../../libs/poco/include/Poco/PriorityStrategy.h:81
> #11 0x000000000042eefc in Poco::AbstractEvent<ofEventArgs, Poco::PriorityStrategy<ofEventArgs, Poco::AbstractPriorityDelegate<ofEventArgs> >, Poco::AbstractPriorityDelegate<ofEventArgs>, Poco::FastMutex>::notify (this=0xaffaa0, pSender=0x0, args=...) at ../../../libs/poco/include/Poco/AbstractEvent.h:241
> #12 0x000000000042e52f in ofNotifyEvent<ofEvent<ofEventArgs>, ofEventArgs> (event=..., args=...) at ../../../libs/openFrameworks/events/ofEventUtils.h:172
> #13 0x000000000042d188 in ofNotifySetup () at ../../../libs/openFrameworks/events/ofEvents.cpp:110
> #14 0x000000000042a3b8 in ofAppGLFWWindow::runAppViaInfiniteLoop (this=0xa1d800, appPtr=0xaff820) at ../../../libs/openFrameworks/app/ofAppGLFWWindow.cpp:309
> #15 0x0000000000417b9b in ofRunApp (OFSA=...) at ../../../libs/openFrameworks/app/ofAppRunner.cpp:163
> #16 0x000000000041761a in ofRunApp (OFSA=0xaff820) at ../../../libs/openFrameworks/app/ofAppRunner.cpp:102
> #17 0x0000000000416f5c in main () at src/main.cpp:11

Can anyone give me some hint?
Thanks in advance

EDIT: I finally managed to solve this by downloading openframeworks again and installing everything. stil have no clue what the problem was though!