ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
691 stars 158 forks source link

gl4es (ES1 or ES2) crashes with neverball #208

Open clort81 opened 4 years ago

clort81 commented 4 years ago

gdb --args ./neverball -l data/map-easy/bumper.sol

bt
#0  0x00000000 in ?? ()
#1  0x0040de86 in sol_load_mesh (mp=0x56a850, bp=0x5545b0, draw=0x488918 <gd+60>, mi=2) at share/solid_draw.c:360
#2  0x0040e13c in sol_load_body (bp=0x56a910, bq=0x5545b0, draw=0x488918 <gd+60>) at share/solid_draw.c:457
#3  0x0040e30a in sol_load_draw (draw=0x488918 <gd+60>, vary=0x4888e0 <gd+4>, s=0) at share/solid_draw.c:525
#4  0x00423fb4 in game_client_init (file_name=0x4a34f8 <level> "map-easy/bumper.sol") at ball/game_client.c:366
#5  0x00428c30 in init_level () at ball/progress.c:103
#6  0x00428dc4 in progress_play (l=0x4a34f8 <level>) at ball/progress.c:136
#7  0x00435be2 in main (argc=3, argv=0xbefff234) at ball/main.c:674

So there may be some problem with gl4es VBOs and how neverball is setting them up? This is beyond my knowledge now.

In case anyone is curious, the VBO setup in share/solid_draw.c is

        glGenBuffers_(1, &mp->vbo);
        glBindBuffer_(GL_ARRAY_BUFFER,         mp->vbo);
        glBufferData_(GL_ARRAY_BUFFER,         vn * sizeof (*vv), vv,
                      GL_STATIC_DRAW);
        glBindBuffer_(GL_ARRAY_BUFFER,         0);

        glGenBuffers_(1, &mp->ebo);
        glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, mp->ebo);
        glBufferData_(GL_ELEMENT_ARRAY_BUFFER, gn * sizeof (*gv), gv,
                      GL_STATIC_DRAW);
        glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, 0);

To get it running, there may be three paths:

Since neverball is well-suited to tablets and phones with accelerometer, a native GL-ES port would be awesome, but I don't have the skills, myself.

Thanks for reading!

ptitSeb commented 4 years ago

That backtrace is missing gl4es calls. Did you built it with debug information?

What version of gl4es and neverball are you using? And on what platform are you running ? I don't reproduce the issue here, but maybe I'm not using correct version (a neverball from github, not updated from a long time).

This looks like a bug in gl4es (as I assume same code works fine on mesa), so I want to fix it.

(converting to native GLES for Android seems a waste of time, gl4es can run on Android, and it's a lot of work anyway).

ptitSeb commented 4 years ago

Also, you have the same crash with ES1 backend? That is strange because ES1 backend doesn't use actual VBO, but simulate them.

What's the code @share/soliddraw.c:360 of your sources? (mine is `glGenBuffers(1, &mp->vbo);`). That means glGenBuffers_ is NULL

ptitSeb commented 4 years ago

Are you sure gl4es is initialized and used?

clort81 commented 4 years ago

According to gdb, calling function before crash is sol_load_mesh in solid_draw.c

static void sol_load_mesh(struct d_mesh *mp,
                          const struct b_body *bp,
                          const struct s_draw *draw, int mi)
{
    struct d_vert *vv = 0;
    struct d_geom *gv = 0;
    int           *iv = 0;

    int oc = draw->base->oc;
    int vn = 0;
    int gn = 0;

    const int gc = sol_count_body(bp, draw->base, mi);

    /* Get temporary storage for vertex and element array creation. */

    if ((vv = (struct d_vert *) calloc(oc, sizeof (*vv))) &&
        (gv = (struct d_geom *) calloc(gc, sizeof (*gv))) &&
        (iv = (int           *) calloc(oc, sizeof (int))))
    {
        int li, i;

        /* Initialize the index remapping. */

        for (i = 0; i < oc; ++i) iv[i] = -1;

        /* Include all matching lump geoms in the arrays. */

        for (li = 0; li < bp->lc; li++)
            sol_mesh_geom(vv, &vn, gv, &gn, draw->base, iv,
                          draw->base->lv[bp->l0 + li].g0,
                          draw->base->lv[bp->l0 + li].gc, mi);

        /* Include all matching body geoms in the arrays. */

        sol_mesh_geom(vv, &vn, gv, &gn, draw->base, iv, bp->g0, bp->gc, mi);

        /* Initialize buffer objects for all data. */

        glGenBuffers_(1, &mp->vbo);
        glBindBuffer_(GL_ARRAY_BUFFER,         mp->vbo);
        glBufferData_(GL_ARRAY_BUFFER,         vn * sizeof (*vv), vv,
                      GL_STATIC_DRAW);
        glBindBuffer_(GL_ARRAY_BUFFER,         0);

        glGenBuffers_(1, &mp->ebo);
        glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, mp->ebo);
        glBufferData_(GL_ELEMENT_ARRAY_BUFFER, gn * sizeof (*gv), gv,
                      GL_STATIC_DRAW);
        glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, 0);

        /* Note cached material index. */

        mp->mtrl = draw->base->mtrls[mi];

        mp->ebc = gn * 3;
        mp->vbc = vn;
    }

    free(iv);
    free(gv);
    free(vv);
}

However thanks to neverball devs, i found neverball builds with gl-es 1 backend natively, on droid4.

neverballcap

If it would help gl4es development to track this down, I am glad to help, but it is not a priority for my Maemo-Leste game ports, now.

Cheers!

ptitSeb commented 4 years ago

Ok, good for you. But I still think you have an issue either with your gl4es build, or with the neverball build because glGenBuffers should not be null.

If you don't plan to continue investigating this issue, then please close the ticket as I cannot dig this one myself.

clort81 commented 4 years ago

I will investigate, as this should work and as you say may be an issue with our gl4es, or even our pvr drivers.