title: glsl dot function indirectly causing a segmentation fault in program
body: <p>Heres my vertex shader code:</p>
  <pre><code>#version 330
  
  layout(location = 0) in vec3 vertex_position;
  layout(location = 0) in vec3 vertex_normal;
  
  //model space
  uniform vec3 toLight;
  
  uniform mat4 model;
  uniform mat4 view;
  uniform mat4 projection;
  
  smooth out vec3 color;
  
  void main()
  {
    gl_Position = projection * view * model * vec4(vertex_position, 1.0f);
    
    vec3 normal = normalize(vertex_normal);
    
    float intensity = dot(normal, toLight);
    intensity = clamp(intensity, 0, 1);
    
    color = vec3(intensity);
  }
  </code></pre>
  <p>In this code I am trying to calculate lighting using the tutorial at <a href="http://arcsynthesis.org/gltut/Illumination/Tutorial%2009.html" rel="nofollow noreferrer">Learning Modern 3D Graphics Programming site</a>. Which is a great book by the way, however the code here is basically identical to the listed code with a couple of names changed, however through the some experimentation, I have discovered something very peculiar. The segmentation fault occurs on the</p>
  <blockquote>
  <p>color = vec3(intensity);</p>
  </blockquote>
  <p>line, I know that because removing that line causes the program to run normally, (except without lighting of course)</p>
  <p>However when I replace the line</p>
  <blockquote>
  <p>float intensity = dot(normal, toLight);</p>
  </blockquote>
  <p>with:</p>
  <blockquote>
  <p>float intensity = 3.14159;</p>
  </blockquote>
  <p>It clamps to 1.0f and everything works fine, the cube is white, same happens if I put a negative number: the number is clamped to zero and the cube is black...</p>
  <p>So this is strange, here's the facts:</p>
  <ul>
  <li>The segmentation fault disappears when removing the line that sets the output vector to the color requested.</li>
  <li>The segmentation fault also disappears when removing the calculation of the dot product</li>
  <li>When the intensity is a constant float, everything works fine.</li>
  <li>setting the color to anything <em>not involving the intensity</em> works fine.</li>
  <li>EDIT: found some interesting info, when setting a variable other than the color variable using the intensity variable works fine, for example <code>vec3 temp = vec3(intensity);</code> doesn't cause a segfault, however setting color to something that is not related to the intensity variable works fine also <code>color = vec3(1.0f);</code> although, if I were to set color to <code>temp</code> it would crash too, this is very strange.</li>
  </ul>
  <p>Any suggestions are greatly appreciated. Thanks</p>
  <p>Also, I would include my opengl, c++ code, but I don't think it's necessary, correct me if I'm wrong.</p>