GPWiki.org
GPWiki.org
It is currently Sat May 25, 2013 7:08 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Aug 21, 2012 3:55 pm 
Hello,

I have a problem compiling this GLSL example. The problematic lines are these:
Code:
    /* The vertex shader */
   char *vsSource = file2string("wave.vert");
   char *fsSource = file2string("wave.frag");
 
   /* Compile and load the program */
 
   GLuint vs, /* Vertex Shader */
         fs, /* Fragment Shader */
         sp; /* Shader Program */
 
 
   vs = glCreateShader(GL_VERTEX_SHADER);
   glShaderSource(vs, 1, &vsSource, NULL);
   glCompileShader(vs);
   printLog(vs);
 
   fs = glCreateShader(GL_FRAGMENT_SHADER);
   glShaderSource(fs, 1, &fsSource, NULL);
   glCompileShader(fs);
   printLog(fs);
 
   free(vsSource);
   free(fsSource);

I get the error "invalid conversion from ‘char**’ to ‘const GLchar** {aka const char**}’ [-fpermissive]" for the lines where I call
glShaderSource(vs, 1, &vsSource, NULL);
and
glShaderSource(fs, 1, &fsSource, NULL);

Strangely it works if I change the first two lines to:
const char *vsSource = file2string("wave.vert");
const char *fsSource = file2string("wave.frag");

However I can't call free(vsSource) and free(fsSource) anymore if I do that


Top
  
 
PostPosted: Tue Aug 21, 2012 7:14 pm 
Shake'n'Baker

Joined: Sun May 27, 2012 6:01 pm
Posts: 62
Hi Max :)

Max wrote:
Strangely it works if I change the first two lines to:
const char *vsSource = file2string("wave.vert");
const char *fsSource = file2string("wave.frag");

However I can't call free(vsSource) and free(fsSource) anymore if I do that


The "const" attribute promises that the value you are pointing to will not change. A const char ** says the value pointed to by the pointer im pointing to wont change. This is not sure in the case above.

In most cases, a conversion from a non-const type to its const type is implicit. However, this can not be done with chars[1]. Some compilers allow it, but yours does not, and is an error in the article.

Explicitly cast your inputs to const will solve this problem.

Code:
    /* The vertex shader */
   char *vsSource = file2string("wave.vert");
   char *fsSource = file2string("wave.frag");
 
   /* Compile and load the program */
 
   GLuint vs, /* Vertex Shader */
         fs, /* Fragment Shader */
         sp; /* Shader Program */
 
 
   vs = glCreateShader(GL_VERTEX_SHADER);
   glShaderSource(vs, 1, (const char **)&vsSource, NULL);
   glCompileShader(vs);
   printLog(vs);
 
   fs = glCreateShader(GL_FRAGMENT_SHADER);
   glShaderSource(fs, 1, (const char **)&fsSource, NULL);
   glCompileShader(fs);
   printLog(fs);
 
   free(vsSource);
   free(fsSource);


All the best,
Mikey

[1] http://c-faq.com/ansi/constmismatch.html


Top
 Profile  
 
PostPosted: Wed Aug 22, 2012 12:10 am 
Wow, thanks cxzuk! :thumbs
Now I can finally use shaders without having a bad conscience for not releasing those strings!


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group