Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8426809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:37:45+00:00 2026-06-10T04:37:45+00:00

It seems I can’t have my GLSL shaders compiled. Once in a while (mainly

  • 0

It seems I can’t have my GLSL shaders compiled. Once in a while (mainly after editing a file), I get following error while compiling:

----- SRC ----- (150 B)
#version 330 core

uniform mat4 mvpMatrix;

in vec4 vertexPosition_modelspace;

void main() {
    gl_Position = mvpMatrix * vertexPosition_modelspace;
}
gp!
----- END -----
SimpleTransform.vertexshader:Vertex shader failed to compile with the following errors:
ERROR: 0:10: error(#132) Syntax error: 'gp' parse error
ERROR: error(#273) 1 compilation errors.  No code generated

It’s quite strange since I swear the file doesn’t contain that awkward gp! part. Nevertheless I investigated it with cat

#version 330 core

uniform mat4 mvpMatrix;

in vec4 vertexPosition_modelspace;

void main() {
    gl_Position = mvpMatrix * vertexPosition_modelspace;
}

and less

#version 330 core

uniform mat4 mvpMatrix;

in vec4 vertexPosition_modelspace;

void main() {
    gl_Position = mvpMatrix * vertexPosition_modelspace;
}

and both of them proved me right.

I wonder what’s causing this strange behaviour.

Here’s link to my project. You should be able to easily compile it by entering src directory and typing make (Linux only). It requires GLFW, GLEW, GLM and GL3.

And the code itself:

Loading shader files

GLuint shader_load(GLenum type, const char filename[]) {
    if ((type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) || !filename) return 0;

    /* wczytywanie pliku shadera */
    FILE *file = fopen(filename, "rb"); 

    //okreslenie rozmiaru pliku
    fseek(file, 0, SEEK_END);   
    uint32 iFileSize = ftell(file);
    fseek(file, 0, SEEK_SET);

    //wczytywanie
    char *tmp = new char[iFileSize];
    memset(tmp, 0, sizeof(tmp));
    uint32 iBytes = (uint32) fread(tmp, sizeof(char), iFileSize, file); 
    fclose(file);   
    if (iBytes != iFileSize) printf("Warning: reading error possible!\n");

    #ifdef _DEBUG_
    printf("----- SRC ----- (%d B)\n%s\n----- END -----\n", iBytes, tmp);
    #endif

    /* przygotowanie shadera */
    GLuint shader = glCreateShader(type);
    glShaderSource(shader, 1, const_cast<const GLchar**>(&tmp), NULL);
    delete[] tmp;
    glCompileShader(shader); //kompilacja shadera

    /* sprawdzenie statusu kompilacji */
    int status = GL_FALSE; 
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);  
    int logsize = 0;
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logsize);
    char *log = new char[logsize];
    glGetShaderInfoLog(shader, logsize, NULL, log);
    printf("%s:%s", filename, log);         
    delete[] log;
    if (status != GL_TRUE)  return 0;

    return shader;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:37:46+00:00Added an answer on June 10, 2026 at 4:37 am

    FIRST OFF Switch to C++ instead of C-with-a-cpp extension to avoid shipwrecks like this.

    Analysis:


    Running under valgrind shows

    ==15579== Invalid read of size 1
    ==15579==    at 0x5B95C65: vfprintf (vfprintf.c:1623)
    ==15579==    by 0x5B9E768: printf (printf.c:35)
    ==15579==    by 0x4019C1: shader_load(unsigned int, char const*) (shaders.cpp:88)
    ==15579==    by 0x401B30: program_create(char const*, char const*) (shaders.cpp:120)
    ==15579==    by 0x401D65: main (in /tmp/ogl-jg-3/test)
    ==15579==  Address 0xb3018a6 is 0 bytes after a block of size 150 alloc'd
    ==15579==    at 0x4C2864B: operator new[](unsigned long) (vg_replace_malloc.c:305)
    ==15579==    by 0x401961: shader_load(unsigned int, char const*) (shaders.cpp:81)
    ==15579==    by 0x401B30: program_create(char const*, char const*) (shaders.cpp:120)
    ==15579==    by 0x401D65: main (in /tmp/ogl-jg-3/test)
    

    It tells you exactly that it tries to read beyond the end of the buffer tmp which is allocated in line 81. It seems you are somehow assuming it is null-terminated. Which it isn’t. Add that:

    //wczytywanie
    char *tmp = new char[iFileSize+1];
    memset(tmp, 0, (iFileSize+1)*sizeof(char));
    uint32 iBytes = (uint32) fread(tmp, sizeof(char), iFileSize, file); 
    fclose(file);   
    if (iBytes != iFileSize) printf("Warning: reading error possible!\n");
    
    #ifdef _DEBUG_
        printf("----- SRC ----- (%d B)\n%s\n----- END -----\n", iBytes, tmp);
    #endif
    

    And I get semi-decent output. The GL window stays blank, though

    Update

    To make it clearer what I meant by switch to C++ here’s the idea:

    GLuint shader_load(GLenum type, const char filename[]) {
        if ((type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) || !filename) return 0;
    
        GLuint shader = glCreateShader(type);
        std::string src;
        {
            /* wczytywanie pliku shadera */
            std::ifstream ifs(filename, std::ios::binary);
            if (!std::getline(ifs, src, '\0'))
                std::cerr << "Warning: reading error possible!\n";
        }
    
    #ifdef _DEBUG_
        std::cout << "----- SRC ----- " << src.size() << " B \n" << src << "\n----- END -----\n";
    #endif
    
        /* przygotowanie shadera */
        const GLchar* sources[] = { src.c_str() };
        glShaderSource(shader, 1, sources, NULL);
        glCompileShader(shader); //kompilacja shadera
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple example I can't seems to get working : MERGE INTO
It seems JAXB can't read what it writes. Consider the following code: interface IFoo
It seems I can't easily have an XSD declaration for this simple XML <root>
Very strange bug I can't seems to figure out. I am trying to get
After reading some stuff it seems I can map the SMBIOS memory and parse
I have looked in a lot of places but it seems i can't find
I have read hackchina and codeproject examples but it seems I can not figure
I have googled a lot and it seems UseCMSCompactAtFullCollection can only be used in
using PHPMailer's AddAttachment method on PHP 5, it seems I can't get any mail
We have multiple academic licenses for Rational Rhapsody but it seems we can still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.