I've checked to see if my C string is my file... and it is. What I mean as Objective-C being my language is that I've been programming with Objective-C for years, while I've only been using C++ recently. I'm using iostream to read the file because Objective-C doesn't play nice with glfw (my window management system.) I'm not currently concerned with performance, so I've left the leak alone for now.
Passing in the size doesn't seem to fix the problem. I did this to get the size of the C String for the final parameter:
GLint sizeOfContents = sizeof(contentsConst);
I passed this in as a pointer for the final parameter. (&sizeOfContents)
So I'm still not sure why this doesn't work. What's odd to me is that sometimes the shaders will compile and other times the shaders won't compile.
I'll try GCements method of loading the shaders and see if that makes a difference.
That's wrong. sizeof(contentsConst) will be the size of a pointer (typically 4 or 8), not the size of the array which it points to. The size of the string can be obtained from the variable "size" which you used to allocate the array.
Originally Posted by Blakeasd
Alternatively, you could null-terminate the string by allocating size+1 bytes and setting contents[size]='\0'.
If you do neither, glShaderSource() won't know where the string ends, and it will try to parse whatever follows it in memory.
It worked! Thanks so much for the help GClements and Alfonse! I obtained the length of the C string (not the pointer this time) like this:
GLint arraySize = (GLint)size;
and passed it in as a reference like so: &arraySize