u16 on Android propably signed

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
porcus
Posts: 149
Joined: Sun May 27, 2007 6:24 pm
Location: Germany

u16 on Android propably signed

Post by porcus »

I noticed when I created a SMeshBuffer (16 Bit Indices) with 256^2=65536 Vertices (256x256 regular grid) that it worked well on Linux but not on Android. After some experimenting I noticed that the maximum amount of Vertices in a regular grid is 181^2 (181x181 grid), if u16 is signed this would be the expected result because sqrt(65536/2)=181.019335984 .

I've used the following code (with sampleAmount set to 256 or 181):

Code: Select all

 
        SMesh* m =new SMesh();
        SMeshBuffer* mb = new SMeshBuffer();
        m->addMeshBuffer(mb);
        mb->drop();
        mb->Vertices.reallocate(sampleAmount*sampleAmount);
        mb->Vertices.set_used(sampleAmount*sampleAmount);
        mb->Indices.reallocate(3*2*(sampleAmount-1)*(sampleAmount-1));
        mb->Indices.set_used(3*2*(sampleAmount-1)*(sampleAmount-1));
        for(int i=0; i<sampleAmount*sampleAmount; i++){
            mb->Vertices[i] = S3DVertex(-1.f+(float)(i%sampleAmount)*2.f/(float)(sampleAmount-1), 0.f, 1.f-(float)(i/sampleAmount)*2.f/(float)(sampleAmount-1), 0.f, 1.f, 0.f, SColor(255,255,255,255), (float)(i%sampleAmount)/(float)(sampleAmount-1), (float)(i/sampleAmount)/(float)(sampleAmount-1));
        }
        int i = 0;
        for(int x=0; x<(sampleAmount-1); x++){//vom letzten Vertex einer Spalte/Reihe geht kein Dreieck aus, daher (sampleAmount-1)
            for(int y=0; y<(sampleAmount-1); y++){
                //int i = (x+y*sampleAmount)*3*2;
                mb->Indices[i] = x+y*sampleAmount;
                mb->Indices[i+1] = (x+1)+y*sampleAmount;
                mb->Indices[i+2] = x+(y+1)*sampleAmount;
                mb->Indices[i+3] = (x+1)+y*sampleAmount;
                mb->Indices[i+4] = (x+1)+(y+1)*sampleAmount;
                mb->Indices[i+5] = x+(y+1)*sampleAmount;
                i += 6;
            }
        }
        mb->recalculateBoundingBox();
        mb->setHardwareMappingHint(EHM_STATIC, EBT_VERTEX_AND_INDEX);
        mb->setDirty(EBT_VERTEX_AND_INDEX);
        m->recalculateBoundingBox();
        m->setHardwareMappingHint(EHM_STATIC, EBT_VERTEX_AND_INDEX);
        m->setDirty(EBT_VERTEX_AND_INDEX);
 
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: u16 on Android propably signed

Post by hendu »

Test it directly:

Code: Select all

#include <irrlicht.h>
 
using namespace irr;
 
int main() {
        u16 tmp = -5;
        printf("%d\n", tmp);
        return 0;
}
 
porcus
Posts: 149
Joined: Sun May 27, 2007 6:24 pm
Location: Germany

Re: u16 on Android propably signed

Post by porcus »

Ok I have tested it. Surprisingly it is not signed.
But why does it behave this way on android? Has anybody an idea?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: u16 on Android propably signed

Post by hendu »

If the source is correct, then the destination must be faulty. Ie your GLES driver, or perhaps irr tells the driver to use signed short (doubtful).
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: u16 on Android propably signed

Post by Nadro »

It looks like a driver problem. Irrlicht uses GL_UNSIGNED_SHORT for 16BIT indices in all OpenGL drivers.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply