View Full Version : glGenTextures() causes segmentation fault
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
I get a segmentation fault! Any ideas why this would be? Thanks in advance for any help,
Is it an array your passing to glGenTextures ?
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:
I suspect this isn't an OpenGL problem, but a my-bad-coding problem. Any more ideas?
07-28-2001, 07:08 PM
You were right - it's a your-bad-coding problem http://www.opengl.org/discussion_boards/ubb/tongue.gif glGenTextures is trying to write to the textureObject member, right? But textureObject is a private member so glGenTextures isn't allowed to access it http://www.opengl.org/discussion_boards/ubb/wink.gif 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.
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!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.