ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello
I'm trying to load an image using OpenIL.But the problem is, i keep getting segmentation faults.
All the OpenIL functions are causing an segmentation fault.First i thought that i didn't compiled my libraries right(i did ran ldconfig after running make install when compiling the libraries), so i downloaded the precompiled libraries and let g++ get the libraries from that place, but that didn't solved the problem too.
How i compile the source code:
Segmentation faults are usually caused by touching memory in some way that you do not have the right to touch. Perhaps you are passing an uninitialized pointer to OpenIL and it expects it to point to an already allocated array?
As always, code examples would help greatly in tracking down the problem. Perhaps you could use gdb to find where the crash occurs, then post the code from that area.
The strange thing is, i copied the things from the tutorial of OpenIL.
From the tutorial:
Quote:
Image Names
DevIL's image name system is virtually identical to OpenGL's texture name system. First, you need an image name variable:
ILuint ImageName;
Next, generate an image name to be put in this variable:
ilGenImages(1, &ImageName);
Now bind this image name so that DevIL performs all subsequent operations on this image:
ilBindImage(ImageName);
Creating images is as simple as that. No messy pointers or anything else to mess with. To get an in-depth explanation of image names, read the tutorial on them.
Loading an Image
Loading an image is as simple as it can be with DevIL. For most programs, a simple call to ilLoadImage will suffice. IF the image was not loaded due to any of various reasons, ilLoadImage returns false, else it returns true if the image was successfully loaded.
Code for loading an image.
ilLoadImage("monkey.tga");
Image Information
Of course DevIL would be pretty useless if you could not retrieve information about the image somehow. ilGetInteger serves this purpose very well, allowing you to know pretty much everything about an image. Some useful values to pass as parameters to ilGetInteger are IL_IMAGE_WIDTH, IL_IMAGE_HEIGHT and IL_IMAGE_BPP. All of these and more are defined in DevIL's il.h header.
Code for getting an image's width and height.
ILuint Width, Height;
Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
Image Data
To get a pointer to the image data for your own use, make a call to ilGetData. ilGetData returns a direct pointer to the image data. Do not try to free this pointer when you are done with it, as it does not point to a copy of the image data but to the actual image data. The image data is freed when you delete the image.
Code for getting the image data.
ILubyte *Data = ilGetData();
ylke@hylke:~/openil$ gdb testje
GNU gdb 6.1.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /home/hylke/openil/testje
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
Hmmm... try compiling it with the -g flag, and run it through gdb again to see if it gives more information on where the segfault occurs. Based on the description you posted for OpenIL, and the code fragment, I don't see anything obviously wrong...
Are you using the pixels variable after you get the pointer? Perhaps to as a parameter to glTexImage2D? Maybe you are supplying the wrong parameters there, causing it to read beyond the end of the array...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.