Segmentation fault (creating texture)

Can someone tell me any possible reasons for a segmentation fault. I am following examples I found.


56 void Texture::loadTexture(const vr::Image *image, int unit){
 57     if(m_image != NULL){
 58         glEnable(GL_TEXTURE_2D);
 59         glGenTextures(1, &m_id);
 60        // glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
 61         glActiveTextureARB(GL_TEXTURE0_ARB+unit);<-chrash!!!!!!!11111
 62         glBindTexture(GL_TEXTURE_2D, m_id); 
 66         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 67         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 68         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 69         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 70         glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 73         glTexImage2D (GL_TEXTURE_2D, 0, m_image->components(),
 74                       m_image->width(), m_image->height(), 0, 
 75                       m_image->format(), GL_UNSIGNED_BYTE, 
 76                       m_image->data());
 78     }                 
 79     unBind();         
 80 }  

Is glActiveTextureARB properly loaded?
My bet is its NULL or other invalid pointer, and thus crashing.
Check your extensions initialization code.

How do I load it? Any key words to search for?

My driver does not support multitexturing. How is this possible? Its a new computer. Multitexturing is like 10 years old?

 58         if (glewGetExtension("GL_ARB_multitexture") != GL_TRUE) {
 59             std::cerr << "Driver does not support GL_ARB_multitexture" << std::endl;
 60             exit(1);
 61         }

This is my hard ware. It should support 8 texture units?

If your GL version is 3.2 or greater, and you’re creating your OpenGL context with attributes, make sure you ask for a compatibility context.

Thank you for your replay!

“support for OpenGL 3.1”.

So multitexturing is not possible on this GPU?

Your GPU is good enough.
How do you get glActiveTextureARB function pointer ?


I am not sure what you mean but I searched and found

/* Declare function pointers */ 


but do I have do something similar. I have done multiteturing before on another computer and did not have to worry about this.

Where(if?) should I do this?

Hi ei05tbe - two thoughts in case any would help you:

  • On Linux, make sure you have the HW vendor drivers installed. The open source drivers usually are very simple. Once you have the right driver installed, everything should work transparently.

  • On Windows, using GL is a pain, you have to do all kinds of wglGetProcAddress nonsense to use anything past very early versions of GL. If you don’t do that it will crash. It is usually easier to mess with OpenGL on Linux.

Let us forget about windows :).

Should I go to the HW vendor homepage to gt the drivers because now I am just using the open source.

Are all drivers available for linux?

All help appreciated.

Edit: Sorry for writing a lot. I think I found it. Its on Nvidias homepage. not Gigabyte. Now I have to figure out how to install it :slight_smile:

Well it depends on your distribution. On many modern distros there are packages for both NV and ATI (AMD) available through your distros repositories, and then they’ll also be automatically updated for you, whereas if you download them yourself from the vendor you may have to update them by hand when you update your kernel. For my distro the packages were called nvidia-current, nvidia-current-modaliases, nvidia-common, nvidia-settings. I did “sudo apt-get install” of those and I was up and running after a reboot.

The HW vendor drivers will also give you a large boost in 3D performance.

ei05tbe, you should tell us if glActiveTextureARB is NULL.
Apparently you use glew, if you do it correctly it should be easy to use glActiveTextureARB.

Just be sure to call glewInit() after the creation of a valid GL context :

Well I downloaded the file but are still trying to install it

ERROR: You appear to be running an X server; please exit X before			
		 installing.  For further details, please see the section INSTALLING   
		 THE NVIDIA DRIVER in the README available on the Linux driver		 
		 download page at


Just execute the installer binary (as root) wtih X shut down,
You must have kernel source package installed (NVIDIA driver must be able to compile kernel module)

If Your distro has ‘nouveau’ open source driver installed and loaded,
NVIDIA driver installation may fail. (I run into this on Slackware 13)
solution to this problem is to blacklist nouveau kernel module.

To exit from X hit ctrl+alt+backspace (X server reset, on some distros (Slackware) it shuts down X server)

1.Is this correct to install the kernel source?

“sudo aptitude install linux-source”

2.“To exit from X hit ctrl+alt+backspace”

This is disabled in the latest versions of Ubuntu? I found some guides to turn this functionality on but they are for earlier version (I have 10.4). Is there any other way to do this?

  1. I will remove the open source driver.

Also how did you blacklist it(nouvea)?

desktop:~/Hämtningar# echo "blacklist nouveau" >> /etc/modprobe.d/50-blacklist.conf


Yes it is NULL

 67         if(glActiveTextureARB== NULL){
 68             cout << "NULL" << endl;
 69         }

gives NULL

Finally I think I understand the problem. I have a global variable. This Scene is created before anything(glew) is initialized in main. I guess what I have to do is make it a pointer and initialize it in main after my glewInint();

Scene m_scene;<--this one is created first

int main(){
.....code ...glewInit()....etc...

I am not 100% sure but I thin k this is the case.

Thank you all!

That was the case. Now I am back on track.

Thanks again!

You are using ubuntu, right?

 sudo /etc/init.d/gdm stop

or (if You are on KDE)

sudo /etc/init.d/kdm stop

should stop the X server.

install the driver from console.

to start X again type:

sudo /etc/init.d/gdm start

btw. Ubuntu should have prepackaged NVIDIA diver, here is the guide how to install it:

Use [EDIT] button.