LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2005, 09:00 AM   #1
hylke
Member
 
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329

Rep: Reputation: 30
OpenIL -> segmentation fault


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:
Code:
g++ testje.cpp -L/usr/X11R6/lib -lglut -lGLU -lGL -lXi -lXmu -lX11 -lXext -lm -L/home/hylke/Desktop/DevIL/lib -lIL -lILU -o testje
So does anyone know what could went wrong?
Thanx Hylke
 
Old 01-02-2005, 09:19 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.

Last edited by deiussum; 01-02-2005 at 09:21 AM.
 
Old 01-03-2005, 05:12 AM   #3
hylke
Member
 
Registered: Apr 2004
Location: the Netherlands
Distribution: Ubuntu 7.04
Posts: 329

Original Poster
Rep: Reputation: 30
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();
from http://openil.sourceforge.net/tuts/tut_step/index.htm

My code:
Code:
      ILuint ImageName;
        ilGenImages(1, &ImageName);
        ilBindImage(ImageName);
        if(! ilLoadImage("testje.png"))
                cout << "Kan testje.png niet laden :'(\n";
        ILuint width, height;
        width = ilGetInteger(IL_IMAGE_WIDTH);
        height = ilGetInteger(IL_IMAGE_HEIGHT);
        cout << "Width: " << width << endl;
        cout << "Height: " << height << endl;

        pixels = ilGetData();
gdb:
Quote:
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 ?? ()
I hope i've provided you enough information
Hylke
 
Old 01-03-2005, 10:22 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 04:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 11:13 AM
segmentation fault ntduongntd Linux - General 4 11-29-2004 12:00 PM
Segmentation fault santhosh_o Programming 3 10-26-2004 05:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration