I'm trying to write a Wavefront OBJ file viewer in Objective-C, that is capable of loading meshes/materials/shaders from files. I've created classes for shaders and shader programs, and I'm trying to create an OpenGL shader program object as part of my shader program class's init method:
- (id)initWithVertexShader:(NSString *)vshader FragmentShader:(NSString *)fshader {
self = [super init];
if (self) {
SRShader* shaders[2] = {
[[SRShader alloc] initWithFilename:vshader Type:GL_VERTEX_SHADER Source:nil],
[[SRShader alloc] initWithFilename:fshader Type:GL_FRAGMENT_SHADER Source:nil]
};
program = glCreateProgram();
for (int i = 0; i < 2; i++) {
SRShader* s = shaders[i];
NSError* e = nil;
s.source = [NSString stringWithContentsOfFile:s.filename encoding:NSUTF8StringEncoding error:&e];
if (!e) {
NSLog(@"Failed to read shader file: %@\n", s.filename);
exit(-1);
}
GLuint shader = [s compile];
... and so on.
However, calling glCreateProgram results in EXC_BAD_ACCESS, as does the call to [SRShader compile], which in turn calls glCreateShader. Does anyone know of any issues with these function calls in Objective-C? Maybe something to do with ARC or calling them in an initialization function?