Results 1 to 5 of 5

Thread: glGenTextures() causes segmentation fault

  1. #1

    glGenTextures() causes segmentation fault

    Hi guys,
    I have created a texture class with a function to read the texture from disk, and a private GLuint member for the texture object. The problem is when I call

    glGenTextures(1, &textureObject);

    I get a segmentation fault! Any ideas why this would be? Thanks in advance for any help,


  2. #2
    Junior Member Newbie
    Join Date
    May 2001

    Re: glGenTextures() causes segmentation fault

    Is it an array your passing to glGenTextures ?

  3. #3

    Re: glGenTextures() causes segmentation fault

    I have my own texture class, and each instance of the class has a private member called GLuint textureObject. I have an array of these texture classes, but the OpenGL texture objects are not in an array.
    I've just tried something else. If in the constructor of the texture class I randomly generate an integer for the texture object I don't have to call glGenTextures(). However, it then seg faults on the next line which reads:

    glBindTextures(GL_TEXTURES_2D, textureObject);

    I suspect this isn't an OpenGL problem, but a my-bad-coding problem. Any more ideas?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Feb 2001

    Re: glGenTextures() causes segmentation fault

    You were right - it's a your-bad-coding problem glGenTextures is trying to write to the textureObject member, right? But textureObject is a private member so glGenTextures isn't allowed to access it You could maybe make glGenTextures a friend function of your texture class but IMHO that would be bad programming practice for reasons I won't go into. If you still want to do it this way, I would probably overload glGenTextures as a member function of your texture class.

    Hope that helps.

  5. #5

    Re: glGenTextures() causes segmentation fault

    I've fixed it! It wasn't due to the private variable, as making it public didn't help. The private variable is OK as glGenTextures is called from within a member function of the texture class.
    The problem was that the code was being called from the loadMap() function (which makes sense) but the map was beng loaded before OpenGL was initialsed and the window created. This had not been a problem until now as there were previosly no OpenGL calls in the loading function. It working now, thanks for your help guys!

Similar Threads

  1. Segmentation fault with cl2.hpp
    By Mike Zhang in forum OpenCL
    Replies: 0
    Last Post: 02-03-2017, 12:22 AM
  2. Segmentation fault
    By genericname in forum OpenGL: Windows
    Replies: 3
    Last Post: 03-11-2012, 10:01 AM
  3. Segmentation fault while using PBO
    By SagoO in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-03-2011, 08:03 AM
  4. Segmentation fault
    By SagoO in forum OpenGL: Basic Coding
    Replies: 28
    Last Post: 01-12-2011, 09:45 AM
  5. Segmentation fault
    By D1G1T4LL in forum OpenGL: Linux
    Replies: 2
    Last Post: 12-09-2003, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean