Forums - glLinkProgram segmentation fault

4 posts / 0 new
Last post
glLinkProgram segmentation fault
david.roerup
Join Date: 21 Apr 15
Posts: 2
Posted: Tue, 2015-04-21 05:39

I get a segmentation fault when linking two quite simple shaders. 

Phone: Sony Xperia Z3 compact.

Test setup: Libgdx on Eclipse, USB debugging.

VERTEX SHADER:

#version 300 es
 
in vec4 a_position;
in vec2 a_faceSize;
in vec4 a_color;
in vec2 a_texCoord0;
 
uniform mat4 u_projTrans;
 
out vec2 v_faceSize;
out vec4 v_color;
out vec2 v_texCoords;
 
void main() {
    v_faceSize = a_faceSize;
    v_color = a_color;
    v_color.a = a_color.a * (255.0/254.0);
    v_texCoords = a_texCoord0;
    gl_Position = u_projTrans * a_position;
}
 
FRAGMENT SHADER:
 
#version 300 es
 
precision highp float;
 
in vec4 v_color;
in vec2 v_texCoords;
in vec2 v_faceSize;
 
uniform sampler2D u_texture;
 
out vec4 fragColor;
 
// THE FOLLOWING LINE SEEMS TO CAUSE THE CRASH.
// IF IT IS MOVED INTO main(), THE CRASH DOES NOT OCCUR
vec2 texPos = v_texCoords * v_faceSize;
 
void main()
{
  fragColor = v_color * texture(u_texture, texPos);
}
 
JAVA CODE:
Base on libgdx. The application main function has been simplified to only include the test case:
 
public class Test extends ApplicationAdapter {
 
  public void create() {
    System.err.format("Test\n");
 
    String vertexShader = Gdx.files.internal("shaders/testVertex.glsl").readString();
    String fragmentShader = Gdx.files.internal("shaders/testFragment.glsl").readString();
 
    compileShaders(vertexShader, fragmentShader);
  }
 
  int vertexShaderHandle;
  int fragmentShaderHandle;
  int program;
  boolean isCompiled;
 
  private void compileShaders (String vertexShader, String fragmentShader) {
    vertexShaderHandle = loadShader(GL20.GL_VERTEX_SHADER, vertexShader);
    fragmentShaderHandle = loadShader(GL20.GL_FRAGMENT_SHADER, fragmentShader);
 
    if (vertexShaderHandle == -1 || fragmentShaderHandle == -1) {
      isCompiled = false;
      return;
    }
 
    program = linkProgram();
    if (program == -1) {
      isCompiled = false;
      return;
    }
 
    isCompiled = true;
  }
 
  private int loadShader (int type, String source) {
    GL20 gl = Gdx.gl20;
    IntBuffer intbuf = BufferUtils.newIntBuffer(1);
 
    int shader = gl.glCreateShader(type);
    if (shader == 0) return -1;
 
    gl.glShaderSource(shader, source);
    gl.glCompileShader(shader);
    gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf);
 
    String infoLog = gl.glGetShaderInfoLog(shader);
    System.err.format("Compile log: %s\n", infoLog);
    System.err.format("...\n");
 
    int compiled = intbuf.get(0);
    if (compiled == 0) {
      return -1;
    }
  
    return shader;
  }
 
  private int linkProgram () {
    GL20 gl = Gdx.gl20;
    int program = gl.glCreateProgram();
    if (program == 0) return -1;
  
    gl.glAttachShader(program, vertexShaderHandle);
    gl.glAttachShader(program, fragmentShaderHandle);
 
    System.err.format("vertexShaderHandle = %d\n", vertexShaderHandle);
    System.err.format("fragmentShaderHandle = %d\n", fragmentShaderHandle);
    System.err.format("program = %d\n", program);
    System.err.format("...\n");
 
    // THE FOLLOWING LINE LEADS TO SEGMENTATION FAULT
    gl.glLinkProgram(program);
 
    ByteBuffer tmp = ByteBuffer.allocateDirect(4);
    tmp.order(ByteOrder.nativeOrder());
    IntBuffer intbuf = tmp.asIntBuffer();
 
    gl.glGetProgramiv(program, GL20.GL_LINK_STATUS, intbuf);
 
    String infoLog = Gdx.gl20.glGetProgramInfoLog(program);
    System.err.format("Program log: %s\n", infoLog);
 
    int linked = intbuf.get(0);
    if (linked == 0) {
      return -1;
    }
 
    return program;
  }
 
  public void pause() {
  }
 
  public void resize(int width, int height) {
  }
 
  public void render() {
  }
 
  public void dispose() {
  }
}
 
LOG (logcat):
 
04-21 15:00:57.872: W/ResourceType(10824): Found multiple library tables, ignoring...
04-21 15:00:57.912: I/Adreno-EGL(10824): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013_msm8974_LA.BF.1.1.1_RB1__release_AU ()
04-21 15:00:57.912: I/Adreno-EGL(10824): OpenGL ES Shader Compiler Version: E031.25.03.00
04-21 15:00:57.912: I/Adreno-EGL(10824): Build Date: 01/21/15 Wed
04-21 15:00:57.912: I/Adreno-EGL(10824): Local Branch: mybranch7061829
04-21 15:00:57.912: I/Adreno-EGL(10824): Remote Branch: quic/LA.BF.1.1.1_rb1.7
04-21 15:00:57.912: I/Adreno-EGL(10824): Local Patches: NONE
04-21 15:00:57.912: I/Adreno-EGL(10824): Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013 +  NOTHING
04-21 15:00:57.954: I/AndroidInput(10824): sensor listener setup
04-21 15:00:57.970: D/OpenGLRenderer(10824): Render dirty regions requested: true
04-21 15:00:57.978: D/Atlas(10824): Validating map...
04-21 15:00:58.000: I/Adreno-EGL(10824): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013_msm8974_LA.BF.1.1.1_RB1__release_AU ()
04-21 15:00:58.000: I/Adreno-EGL(10824): OpenGL ES Shader Compiler Version: E031.25.03.00
04-21 15:00:58.000: I/Adreno-EGL(10824): Build Date: 01/21/15 Wed
04-21 15:00:58.000: I/Adreno-EGL(10824): Local Branch: mybranch7061829
04-21 15:00:58.000: I/Adreno-EGL(10824): Remote Branch: quic/LA.BF.1.1.1_rb1.7
04-21 15:00:58.000: I/Adreno-EGL(10824): Local Patches: NONE
04-21 15:00:58.000: I/Adreno-EGL(10824): Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.013 +  NOTHING
04-21 15:00:58.000: I/OpenGLRenderer(10824): Initialized EGL, version 1.4
04-21 15:00:58.021: D/OpenGLRenderer(10824): Enabling debug mode 0
04-21 15:00:58.044: W/GL2JNIView(10824): creating OpenGL ES 2.0 context
04-21 15:00:58.058: I/GL2(10824): all initialized 2
04-21 15:00:58.059: I/AndroidGraphics(10824): OGL renderer: Adreno (TM) 330
04-21 15:00:58.059: I/AndroidGraphics(10824): OGL vendor: Qualcomm
04-21 15:00:58.059: I/AndroidGraphics(10824): OGL version: OpenGL ES 3.0 [email protected] [email protected] (CL@)
04-21 15:00:58.059: I/AndroidGraphics(10824): OGL extensions: GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_sync GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_filter_anisotropic GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query 
04-21 15:00:58.059: W/Adreno-EGL(10824): <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
04-21 15:00:58.059: W/Adreno-EGL(10824): <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
04-21 15:00:58.059: I/AndroidGraphics(10824): framebuffer: (5, 6, 5, 0)
04-21 15:00:58.059: I/AndroidGraphics(10824): depthbuffer: (16)
04-21 15:00:58.060: I/AndroidGraphics(10824): stencilbuffer: (0)
04-21 15:00:58.060: I/AndroidGraphics(10824): samples: (0)
04-21 15:00:58.060: I/AndroidGraphics(10824): coverage sampling: (false)
04-21 15:00:58.064: I/AndroidGraphics(10824): Managed meshes/app: { }
04-21 15:00:58.065: I/AndroidGraphics(10824): Managed textures/app: { }
04-21 15:00:58.065: I/AndroidGraphics(10824): Managed cubemap/app: { }
04-21 15:00:58.068: I/AndroidGraphics(10824): Managed shaders/app: { }
04-21 15:00:58.068: I/AndroidGraphics(10824): Managed buffers/app: { }
04-21 15:00:58.069: W/System.err(10824): Test
04-21 15:00:58.078: W/System.err(10824): Compile log: 
04-21 15:00:58.078: W/System.err(10824): ...
04-21 15:00:58.081: W/System.err(10824): Compile log: 
04-21 15:00:58.081: W/System.err(10824): ...
04-21 15:00:58.081: W/System.err(10824): vertexShaderHandle = 1
04-21 15:00:58.081: W/System.err(10824): fragmentShaderHandle = 2
04-21 15:00:58.081: W/System.err(10824): program = 3
04-21 15:00:58.081: W/System.err(10824): ...
04-21 15:00:58.082: A/libc(10824): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 10857 (GLThread 17101)
04-21 15:00:58.087: I/Timeline(10824): Timeline: Activity_idle id: android.os.BinderProxy@32caa99d time:99198433
 

 

  • Up0
  • Down0
Ayo Moderator
Profile picture
Join Date: 23 Jan 15
Posts: 31
Posted: Thu, 2015-05-21 16:50

Hello David, and apologies for the late response.

We were able to reproduce the issue and it is being investigated.

We'll keep you informed of any resolution regarding the segmentation fault.

Many thanks for the report.

 

  • Up0
  • Down0
Ayo Moderator
Profile picture
Join Date: 23 Jan 15
Posts: 31
Posted: Tue, 2015-05-26 15:36

Hello David.

The problem is caused by the use of the non constant initializers "v_texCoords" and "v_faceSize":

// THE FOLLOWING LINE SEEMS TO CAUSE THE CRASH.
// IF IT IS MOVED INTO main(), THE CRASH DOES NOT OCCUR
vec2 texPos = v_texCoords * v_faceSize;
 
Refer to page 40 of this document:
 
 

It reads:

"In declarations of global variables with no storage qualifier or with a const qualifier, any initializer must be a constant expression."

The compiler should not crash with a segmentation fault, and should have returned errors of the form:

ERROR: 0:36: 'v_texCoords' : Only consts or uniforms can be used in a global initializer
ERROR: 0:36: 'v_faceSize' : Only consts or uniforms can be used in a global initializer
ERROR: 2 compilation errors.  No code generated.

 

That will be fixed, however even though other compilers might support the initialization of the "texPos" with non constant expressions, it is unlikely that will be changed. Sorry for the bad news.

  • Up0
  • Down0
david.roerup
Join Date: 21 Apr 15
Posts: 2
Posted: Tue, 2015-06-02 03:44

Hello Ayo,

Thank you for your feedback. I am not very experienced, so I am not very surprised that I had made an error.

I am quite happy with your solution, it is not bad news at all. The shader code can be changed to follow specifications, so the main thing is that the compiler can tell me what I do wrong.

Best regards,

David

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.