SFML community forums

Help => General => Topic started by: stewart on September 15, 2013, 01:15:55 pm

Title: Error when attempting to load a shader from a file
Post by: stewart on September 15, 2013, 01:15:55 pm
(C++ and SFML noob)

Been looking at this for 4 hours now. Got me beat. I can't load a shader from a file. I am running VS Express 2012, SFML 2.1, Windows 8.

My code:

        sf::Shader shader;
        shader.loadFromFile("C:\\Users\\Stewart\\Documents\\Visual Studio 2012\\Projects\\Stewmines\\bloom",  sf::Shader::Fragment);
 


The shader. (Downloaded and pasted). I just wanted to get something working before I started hacking away.
uniform sampler2D bgl_RenderedTexture;

void main()
{
   vec4 sum = vec4(0);
   vec2 texcoord = vec2(gl_TexCoord[0]);
   int j;
   int i;

   for( i= -4 ;i < 4; i++)
   {
        for (j = -3; j < 3; j++)
        {
            sum += texture2D(bgl_RenderedTexture, texcoord + vec2(j, i)*0.004) * 0.25;
        }
   }
       if (texture2D(bgl_Rend eredTexture, texcoord).r < 0.3)
    {
       gl_FragColor = sum*sum*0.012 + texture2D(bgl_RenderedTexture, texcoord);
    }
    else
    {
        if (texture2D(bgl_RenderedTexture, texcoord).r < 0.5)
        {
            gl_FragColor = sum*sum*0.009 + texture2D(bgl_RenderedTexture, texcoord);
        }
        else
        {
            gl_FragColor = sum*sum*0.0075 + texture2D(bgl_RenderedTexture, texcoord);
        }
    }
}
 

When my program executes the loadFromFile member function I get the following error

Unhandled exception at 0x6E31DD22 (msvcr110.dll) in Stewmines.exe: 0xC0000005: Access violation reading location 0x00995000.
 

The output window gives me the following garble. Note the total output is about 100 - 200 lines however I have included only the last two as each line is the same as the first.
&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯
&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;¯&#9632;^&#8616;ÏP&#9787;´ &#9829;î û î û 8 û 8
 û  PÖ
 

The output that VS gives me. Again I have only added the last few lines to keep this post sane :).

First-chance exception at 0x6E31DD22 (msvcr110.dll) in Stewmines.exe: 0xC0000005: Access violation reading location 0x00995000.
Unhandled exception at 0x6E31DD22 (msvcr110.dll) in Stewmines.exe: 0xC0000005: Access violation reading location 0x00995000.
The thread 0x9f4 has exited with code 0 (0x0).
The thread 0x1524 has exited with code 0 (0x0).
The program '[8024] Stewmines.exe' has exited with code 0 (0x0).
 
Title: Re: Error when attempting to load a shader from a file
Post by: Laurent on September 15, 2013, 02:36:08 pm
Make sure that you don't mix debug and release, as stated in the tutorial.
Title: Re: Error when attempting to load a shader from a file
Post by: stewart on September 16, 2013, 02:31:08 am
Make sure that you don't mix debug and release, as stated in the tutorial.

Thanks Laurent. I have a feeling I am liking to release form debug.  Will check at home tonight.
Title: Re: Error when attempting to load a shader from a file
Post by: stewart on September 16, 2013, 10:31:58 am
Make sure that you don't mix debug and release, as stated in the tutorial.

Confirmed.  To all who encounter this issue: Make sure that you link to the debug libs and not the release libs. This can be done in your project settings under VS 2012. Debug libs have a -d appended to the file name.
Title: Re: Error when attempting to load a shader from a file
Post by: Laurent on September 16, 2013, 10:38:06 am
... or just read the tutorials carefully :P