Hello this code seems so well done and yet I'm getting this weird access violation error when I use anything but 0 in glShaderSources 2nd argument :
glShaderSource( fragshader, 0, fragfilebuff, NULL ); If I use lenofstr or any other number then 0 it calls up an error like this :
I have no idea for the life of me why this is happpening I've updated my drivers , I've even tried messing around with glewInit(); too see if it's something to do with that but no luck what so ever.
This nvidia dll has some problem with my code and I don't know why?...
void LoadShaders(const char *fragshaderfn, const char *vertshaderfn) { FILE *fragfile; const GLchar *fragfilebuff[256] = { 0 }; fopen_s(&fragfile, fragshaderfn, "r"); fread(fragfilebuff, sizeof(char), sizeof(char) * 256, fragfile); printf(fragfilebuff); GLsizei lenofstr = strlen(fragfilebuff); printf("this is the length -> %d", lenofstr); GLuint fragshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragshader, 0, fragfilebuff, NULL); glCompileShader(fragshader); }; Here's the complete source :
#include <SDL.h> #include <GL/glew.h> #include <SDL_opengl.h> #include <stdio.h> #include <conio.h> #define SCREEN_HEIGHT 480 #define SCREEN_WIDTH 640 SDL_Renderer *mainrenderer; SDL_Window *mainwindow; SDL_Event event; bool running = true; void LoadShaders(const char *fragshaderfn, const char *vertshaderfn) { FILE *fragfile; const GLchar *fragfilebuff[256] = { 0 }; fopen_s(&fragfile, fragshaderfn, "r"); fread(fragfilebuff, sizeof(char), sizeof(char) * 256, fragfile); printf(fragfilebuff); GLsizei lenofstr = strlen(fragfilebuff); printf("this is the length -> %d", lenofstr); GLuint fragshader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragshader, lenofstr, fragfilebuff, NULL); glCompileShader(fragshader); }; int main(int argc , char **argv) { SDL_Init(SDL_INIT_EVERYTHING); mainwindow = SDL_CreateWindow( "C OpenGL Engine", 300, 300, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL ); SDL_GLContext maincontext = SDL_GL_CreateContext(mainwindow); SDL_GL_MakeCurrent(mainwindow, maincontext); glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); if (SDL_GL_SetSwapInterval(1) < 0) { printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError()); } LoadShaders("ffile.frag", ""); glClearColor(0.0, 0.0, 0.0, 1.0); while (running == true) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: SDL_GL_DeleteContext(maincontext); SDL_Quit(); return 0; break; } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); SDL_GL_SwapWindow(mainwindow); } SDL_GL_DeleteContext(maincontext); SDL_DestroyWindow(mainwindow); SDL_Quit(); return 0; } All help would be appreciated I am using C , SDL 2.0 and OpenGL 3.3+ , MSVC 2015 , Win10 64bit

glShaderSource( fragshader, 1, &fragfilebuff, NULL );if your string has a0x00at the end. ReplaceNULLwith&fragfilelenif not. \$\endgroup\$