问题
I'm currently working on a game project using cocos2dx-2.2.2.
When I do some operation(read textures from file and show a dialog), the application may force close or the screen will freeze(the network thread is still running though).
It happens on nexus occasionaly, but rarely happens on other devices.
the log is as follow:
12-29 15:23:01.169: E/Surface(2128): queueBuffer: error queuing buffer to SurfaceTexture, -22
12-29 15:23:01.169: W/Adreno-EGLSUB(2128): <SwapBuffers:1340>: failed to queueBuffer
12-29 15:23:01.169: W/Adreno-EGL(2128): <qeglDrvAPI_eglSwapBuffers:3809>: EGL_BAD_SURFACE
12-29 15:23:01.204: E/Parcel(2128): Parcel::writeDupFileDescriptor failed:
12-29 15:23:01.204: E/Parcel(2128): fd=1002 flags=0 err=0(Success)
12-29 15:23:01.204: E/Parcel(2128): dupFd=-1 dupErr=24(Too many open files) flags=-1 err=9(Bad file number)
12-29 15:23:01.204: E/Parcel(175): dup failed in Parcel::read, fd 0 of 1
12-29 15:23:01.204: E/Parcel(175): dup(-2147483647) = -1 [errno: 9 (Bad file number)]
12-29 15:23:01.204: E/Parcel(175): fcntl(-2147483647, F_GETFD) = -1 [errno: 9 (Bad file number)]
12-29 15:23:01.204: E/Parcel(175): flat 0x0 type 0
12-29 15:23:01.216: D/Parcel(175): #00 pc 0000cff1 /system/lib/libutils.so (android::CallStack::update(int, int)+52)
12-29 15:23:01.216: D/Parcel(175): #01 pc 0000d107 /system/lib/libutils.so (android::CallStack::CallStack(char const*, int)+38)
12-29 15:23:01.216: D/Parcel(175): #02 pc 00023513 /system/lib/libbinder.so (android::Parcel::read(android::Parcel::FlattenableHelperInterface&) const+246)
12-29 15:23:01.216: D/Parcel(175): #03 pc 00033035 /system/lib/libgui.so (android::BnGraphicBufferProducer::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+568)
12-29 15:23:01.216: D/Parcel(175): #04 pc 0001a6d9 /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+60)
12-29 15:23:01.216: D/Parcel(175): #05 pc 0001f787 /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+582)
12-29 15:23:01.216: D/Parcel(175): #06 pc 0001f8ab /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+38)
12-29 15:23:01.216: D/Parcel(175): #07 pc 0001f8ed /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+48)
12-29 15:23:01.216: D/Parcel(175): #08 pc 00023a5b /system/lib/libbinder.so
12-29 15:23:01.216: D/Parcel(175): #09 pc 000104d5 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+112)
12-29 15:23:01.216: D/Parcel(175): #10 pc 00010045 /system/lib/libutils.so
12-29 15:23:01.216: D/Parcel(175): #11 pc 000162e3 /system/lib/libc.so (__pthread_start(void*)+30)
12-29 15:23:01.216: D/Parcel(175): #12 pc 000142d3 /system/lib/libc.so (__start_thread+6)
Any ideas where could possibly go wrong?
回答1:
That looks remarkably similar to the error I was getting. Mine was not specific to nexus (although I fixed it working on a Nexus 9). Are you properly closing a FD you are opening? That was my issue.
In my specific scenario: 1) I was opening audio files for OpenSL with:
AAssetManager_open
2) getting a FD with
AAsset_openFileDescriptor
3) calling AAsset_close
on the AAsset, and using the FD.
The problem is there is no corresponding AAsset_closeFileDescriptor, nor mention of closing the FD. I thought it was odd when I originally wrote the code, but assumed that was handled by later methods. However my gut was right and all it was doing was opening more and more FD for audio files as I played them, but never releasing them until an internal limit was hit.
The fix I use is to call:
close(fd);
When I am done with the FD. You can find close in
#include <fcntl.h>
来源:https://stackoverflow.com/questions/27685351/too-many-files-error-on-nexus-5-6-lollipop