PDA

View Full Version : Fatal signal 11 (SIGSEGV) crash and upgrading code to ES 3.0



seaCoder
03-07-2016, 10:17 AM
Hello,
I'm completely new to opengl coding

My issues are two-fold
1. I have a crash dump i have no clue to how solve: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x87c34000 in ... (GLThread 6141)

2. I'm stuck with OpenGL ES 1.0 and unable to convert code to GLES 3.0

Brief background
About a year ago I decided to write a puzzle game on Android. The concept was very simple and I would only be rendering points (no triangles mesh, no triangles, no lines), just points. For this I thought I could do with GL10 and cut out a lot of complexities and update to GLES 3.0 or GLES 2.0 later.

On a very old Android device (Samsung Galaxy s2), I had had absolutely no problems, the code/algorithms/game ran and rendered fine. But on newer devices i have tested so far (no change to code) - Samsung Galaxy S3, S4, S5 - I have the crash dump stated in (1) above. It seems to indicate writing to memory not yet owned or allocated. It only occurs on the newer devices when i allow the draw code (draws on S2 with no crash)

This lead to my second issue. A friend suggested maybe I need to update to GLES3.0 for the newer devices. Here again I got stuck. All my efforts to update code to es3.0, crash with Fatal signal 11 (SIGSEGV), code 2

My problem is how to resolve this two issues. Since its good to resolve one at a time then the Fatal signal 11 (SIGSEGV), code 2 first


Here is the skeletal (excluding non-relevant) code, many thanks
I also excluded my code attempts in upgrading to GLES3.0, so I can focus on solving first problem: Fatal signal 11 (SIGSEGV) crash first, so that if I can get the code to work on newer devices as it does on Galaxy S2, then I can be rest assured that any version update errors (or crash) that I get is due to my gl code and not the gaming code

Crashed at the lines gl11.glVertexPointer( ... ) and gl11.glDrawArrays( ... )



import java.io.File;
import java.io.FileOutputStream;

import javax.microedition.khronos.egl.EGLConfig;
import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.opengl.GLES30;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
import android.opengl.Matrix;

public class MyGLRenderer implements GLSurfaceView.Renderer {
public static float[] projMatrix = new float[16];// projection
public static float[] viewMatrix = new float[16];// camera
public static float[] matrixs = new float[16];
Context context; // Application's context

DirectGames_Puzzle mainObjects;

public MyGLRenderer(Context context, int NumOfDataBlocks, int dataType ) {
mainObjects = new DirectGames_Puzzle();
mainObjects.initailisations( );
....
mainObjects.saveData( );
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glDisable(GL10.GL_DITHER);
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
if (height == 0) height = 1;
float aspect = (float)width / height;
gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();

GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.0f);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();

// Matrix.frustumM(projMatrix, 0, -aspect, aspect, -10, 10, 10, 10);// matrix set up
// Matrix.setLookAtM(viewMatrix, 0, 0, 0, 3, 0, 0, 0, 0.0f, 1.0f, 0.0f);
}

public synchronized void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

mainObjects.drawObjects( gl );
}
}

// in DirectGames_Puzzle.java, ie mainObjects is instance of DirectGames_Puzzle class

void drawObjects( GL10 gl ){
byteBufferConstruct.draw( gl, ObjectUnits, objArray, ObjectBuffers );
}

// in Ini_Draw_Objs.java, ie byteBufferConstruct is instance of Ini_Draw_Objs class

public void draw( GL10 gl, int numOfUnits, List<CreateObjVertices> dataArray, BufferData ObjBuffers[] ) {
GL11 gl11 = (GL11)gl;

// ...
// [.... wrapping in here byteBuffer excluded to expose relevant code more clearly...]
// ...

gl11.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl11.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl11.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
gl11.glPointSize(1.5f);

for(int i=0; i<= numOfUnits; i++){
gl11.glVertexPointer(3, GL10.GL_FLOAT, 0, ObjBuffers[i].DBuffer); // Crashed here and
gl11.glDrawArrays(ObjBuffers[i].dataMode, 0, ObjBuffers[i].numberOfData ); // Crashed here
}

gl11.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl11.glDisableClientState(GL10.GL_COLOR_ARRAY);
}

lowlande72
06-26-2016, 11:08 AM
Your problem may be glVertexAttribPointer which takes the offset and length in number of floats, where the "GLsizei stride" is given in bytes.

If the stride is specified in floats, the program will generate A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr because glDrawArrays passes a byte sequence to the vertex shader and the pointer for your vertex or normal data (once converted to bytes) will try to read past that per-vertex byte array.

A quick solution if you're willing to stick with ES 3.0 is to multiply your stride by four or, better, multiply by a static constant BYTES_PER_FLOAT = 4.