heap corruption error on Android asset loading of FileUtils


#1

After developing my cocos2d-x game for iOS I’ve been trying to make it run on Android.
I could make it run perfectly on an Sony Xperia Go, but on three other different models, the app crashes with the following error:

  • A/libc(2421): heap corruption detected by dlmalloc

It was not easy to pinpoint the error, but I found out that this occurs while loading the resources on the assets folder. There is nothing wrong with the files on the assets folder, and I could reproduce the error with different files.
The error is returned by FileUtilsAndroid (CCFileUtilsAndroid.cpp) in the following line of isFileExist:

        AAsset* aa = AAssetManager_open(FileUtilsAndroid::assetmanager, s, AASSET_MODE_UNKNOWN);

I am using the latest version of Android NDK, and cocos2d-x 3.0 beta2 (the latest version from github 3.0 RC, has the same problem)

Is there a fix for this?


#2

anyone?


#3

heap related problems are very hard to debug… specially when we don’t master debugging tools.

By enabling in XCode all the memory tools in Product > Scheme > Edit Scheme, and under Diagnostics tab enable all the Malloc settings, Guard Malloc.
With that it was easy to find a bad allocation on my own code, that had nothing to do with cocos2d-x or Android Resources.
I was assigning an object to an array, out of bounds, and corrupting the heap. The error was being catch only of the Android Resources loading.