This has been troubling me for some time; this function doesn't even return, it just segfaults. I specify a correct file location, I check for errors at every possible point in the function, I don't understand?
GLchar* getShaderString(const GLchar* file_path){
FILE* srcfile = NULL;
if(!(srcfile = fopen(file_path, "r")))
return(NULL);
fseek(srcfile, 0l, SEEK_END);
long len;
if((len = ftell(srcfile)) == -1)
return (NULL);
fseek(srcfile, 0l, SEEK_SET);
GLchar* buff;
if(!(buff = malloc(len + 1)))
return (NULL);
fread((GLvoid*)buff, len, 1, srcfile);
fclose(srcfile);
buff[len + 1] = '\0';
return (buff);
}
buff[len + 1] = '\0';
should be:
buff[len] = '\0';
You have len + 1 elements in your array, your last element is at index len.
fopen works on const char* not const GLchar*.
Also, buff[len+1] = '\0'; should be buff[len] = '\0';.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With