Search code examples
java-native-interfacelibgdxdalvik

Error in LibGDX: JNI ERROR (app bug): non-zero capacity for NULL pointer: 80000


I have come across a new error in LibGdx which says non Zero Capacity for Null Pointer! What does this error mean?

E/dalvikvm(28069): JNI ERROR (app bug): non-zero capacity for NULL pointer: 80000


Solution

  • The error is coming from NewDirectByteBuffer at line 2725 (of this copy of) Jni.cpp: https://android.googlesource.com/platform/dalvik/+/3a7af00/vm/Jni.cpp

    Some native code is trying to initialize an NIO DirectByteBuffer, and its passing in an initial size of 80,000 and a NULL pointer. Since that does not make sense (the pointer should be non-NULL) an exception is thrown. The pointer is most likely NULL because the allocation of the 80,000 bytes failed, most likely because your app has run out of memory, or because memory has become so fragmented, the 80k isn't available contiguously.

    Technically, there is a small bug in the caller's code. It should probably have thrown a more direct-to-the-point OutOfMemoryError, but the idea and the end result are the same.

    Since 80k isn't very big, the statistically likely situation is that you have a memory leak (likely of this very object).

    If you have a backtrace from the dalvik log, it may help pin-point where this particular error is coming from. This would be handy for fixing the OutOfMemoryError bug (it could be in Libgdx, or in box2d, or in any of the native libraries used by Android, its impossible to say without more detail). However, the real root of the problem is your memory leak. Use the Eclipse DDMS heap tracking tools to figure out where that problem is coming from.