The Curious Case of the Hero on Android

It turns out that there is a bug in Android 1.5. Well, it's not a bug, it's just some extremely sloppy programming. Remember that we use direct NIO buffers for our vertices and indices. These are actually memory blocks in native heap memory. Each time we call glVertexPointer(), glColorPointer(), or any other of the glXXXPointer() methods, OpenGL ES will try to fetch the native heap memory address of that buffer to look up the vertices to transfer the data to video RAM. The problem on Android 1.5 is that each time we request the memory address from a direct NIO buffer, it will generate a temporary object called PlatformAddress. Since we have a lot of calls to the glXXXPointer() and glDrawElements() methods (remember, the latter fetches the address from a direct ShortBuffer), Android allocates a metric ton of temporary PlatformAdress instances, and there's nothing we can do about it. (Well, there's actually a workaround, but for now we won't discuss it). Let's just accept the fact that using NIO buffers on Android 1.5 is horribly broken and move on.

0 0

Post a comment