' surfaceDestroyed回调+'没有' surfaceDestroyed回调 - '

时间:2015-01-29 01:39:28

标签: android cocos2d-x glsurfaceview

我正在使用cocos2d-x框架调试一个安卓游戏。它必须与第三方的库进行交互,该库提供了一些常见的服务,例如用户登录。库将在我的游戏界面上绘制一些半透明的图标。

当我将游戏中的主页按钮触摸回桌面时,会发生错误。如果我再次触摸游戏图标,游戏的最后一个快照将显示,但无法与之交互。

通常,当我最小化游戏时,eclipse的logcat将打印如下:

01-29 09:13:21.493: D/SdkActivity(21533): ==onPause==
01-29 09:13:21.494: D/ActivityThread(21533): ACT-AM_ON_PAUSE_CALLED ActivityRecord{4227d568 token=android.os.BinderProxy@42179470 {org.cocos2dx.simplegame.uc/cn.uc.gamesdk.SdkActivity}}
01-29 09:13:21.504: D/ActivityThread(21533): ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy@42179470
01-29 09:13:21.506: V/PhoneWindow(21533): DecorView setVisiblity: visibility = 4 ,Parent =ViewRoot{41eb1ab8 org.cocos2dx.simplegame.uc/org.cocos2dx.simplegame.uc.SimpleGame,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{41da5790 I.E..... R....... 0,0-720,1280}
01-29 09:13:21.506: D/ActivityThread(21533): ACT-HIDE_WINDOW handled : 0 / android.os.BinderProxy@41cf9818
01-29 09:13:21.521: I/SurfaceView(21533): updateWindow -- onWindowVisibilityChanged, visibility = 4
01-29 09:13:21.521: I/SurfaceView(21533): Changes: creating=false format=false size=false visible=true left=false top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=false mVisible=true mRequestedVisible=false
01-29 09:13:21.521: I/SurfaceView(21533): Cur surface: Surface(name=null)/@0x41da3990
01-29 09:13:21.526: I/SurfaceView(21533): New surface: Surface(name=null)/@0x41da3a60, vis=false, frame=Rect(0, 0 - 720, 1280)
01-29 09:13:21.526: I/SurfaceView(21533): Callback --> surfaceDestroyed
01-29 09:13:21.526: I/SurfaceView(21533): surfaceDestroyed callback +
01-29 09:13:21.526: I/SurfaceView(21533): surfaceDestroyed callback -
01-29 09:13:21.527: V/SurfaceView(21533): Layout: x=0 y=0 w=720 h=1280, frame=Rect(0, 0 - 720, 1280)
01-29 09:13:21.530: D/GraphicBuffer(21533): create handle(0x5de3b2c8) (w:720, h:1280, f:1)
01-29 09:13:21.532: D/OpenGLRenderer(21533): Flushing caches (mode 0)
01-29 09:13:21.532: D/GraphicBuffer(21533): close handle(0x626af840) (w:720 h:1280 f:1)
01-29 09:13:21.533: D/GraphicBuffer(21533): close handle(0x61ed99d8) (w:720 h:1280 f:1)
01-29 09:13:21.533: D/GraphicBuffer(21533): close handle(0x5de3b2c8) (w:720 h:1280 f:1)
01-29 09:13:21.542: I/SurfaceView(21533): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-29 09:13:21.698: D/OpenGLRenderer(21533): Flushing caches (mode 0)
01-29 09:13:21.699: D/GraphicBuffer(21533): close handle(0x62879c20) (w:720 h:1280 f:1)
01-29 09:13:21.700: D/GraphicBuffer(21533): close handle(0x66fc8b40) (w:720 h:1280 f:1)
01-29 09:13:21.701: D/GraphicBuffer(21533): close handle(0x632cfc78) (w:720 h:1280 f:1)
01-29 09:13:21.702: D/GraphicBuffer(21533): close handle(0x632cff80) (w:720 h:1280 f:1)
01-29 09:13:21.718: W/IInputConnectionWrapper(21533): showStatusIcon on inactive InputConnection
01-29 09:13:21.731: I/SurfaceView(21533): updateWindow -- onWindowVisibilityChanged, visibility = 8
01-29 09:13:21.732: D/OpenGLRenderer(21533): Flushing caches (mode 0)
01-29 09:13:21.736: I/SurfaceView(21533): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-29 09:13:21.737: D/OpenGLRenderer(21533): Flushing caches (mode 0)
...
01-29 09:13:22.162: I/SurfaceView(21533): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-29 09:13:22.162: D/SdkActivity(21533): ==onSaveInstanceState==
01-29 09:13:22.163: D/SdkActivity(21533): ==onStop==
01-29 09:13:22.166: V/PhoneWindow(21533): DecorView setVisiblity: visibility = 4 ,Parent =ViewRoot{41d393e8 org.cocos2dx.simplegame.uc/cn.uc.gamesdk.SdkActivity,ident = 12}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{421b4c40 I.E..... R....... 0,0-720,1280}
01-29 09:13:22.166: D/ActivityThread(21533): ACT-STOP_ACTIVITY_HIDE handled : 0 / android.os.BinderProxy@42179470
01-29 09:13:22.178: D/OpenGLRenderer(21533): Flushing caches (mode 0)

但异常的是,logcat如下:

01-29 09:11:27.378: D/SdkActivity(21256): ==onSaveInstanceState==
01-29 09:11:27.378: D/SdkActivity(21256): ==onPause==
01-29 09:11:27.378: D/ActivityThread(21256): ACT-AM_ON_PAUSE_CALLED ActivityRecord{42028fb0 token=android.os.BinderProxy@41f86658 {com.mf.sglm.uc/cn.uc.gamesdk.SdkActivity}}
01-29 09:11:27.390: D/ActivityThread(21256): ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy@41f86658
01-29 09:11:27.391: V/PhoneWindow(21256): DecorView setVisiblity: visibility = 4 ,Parent =ViewRoot{41eacbd8 com.mf.sglm.uc/com.mf.sglm.uc.SGLM,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{41da0858 I.E..... R.....I. 0,0-720,1280}
01-29 09:11:27.392: D/ActivityThread(21256): ACT-HIDE_WINDOW handled : 0 / android.os.BinderProxy@41cf52b0
01-29 09:11:27.394: I/SurfaceView(21256): updateWindow -- onWindowVisibilityChanged, visibility = 4
01-29 09:11:27.394: I/SurfaceView(21256): Changes: creating=false format=false size=false visible=true left=false top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=false mVisible=true mRequestedVisible=false
01-29 09:11:27.394: I/SurfaceView(21256): Cur surface: Surface(name=null)/@0x41d9e8a0
01-29 09:11:27.399: I/SurfaceView(21256): New surface: Surface(name=null)/@0x41d9e970, vis=false, frame=Rect(0, 0 - 720, 1280)
01-29 09:11:27.399: I/SurfaceView(21256): Callback --> surfaceDestroyed
01-29 09:11:27.399: I/SurfaceView(21256): surfaceDestroyed callback +

似乎'surfaceDestroyed callback +'和'surfaceDestroyed callback-'是一对。但是,当他们中的一个错过时,我找不到什么问题......

1 个答案:

答案 0 :(得分:0)

我找到了问题的原因。

第三方库是异步实现的,需要为每个应用程序接口提供回调函数。我从android主线程(也称为UI线程)调用它的接口,但回调函数在另一个线程而不是主线程中执行。所以我不能在回调函数中做UI事情。

为了知道库的调用已完成并更改游戏UI,我在调用库的接口之前设置了一个标志变量,并在回调函数中更改了变量。然后启动'while(1)'循环检查flag变量,直到它发生变化。

您注意到在调用接口后,我调用库接口的主线程被阻止了。这就是导致问题的原因。

为了解决这个问题,我使用一个计时器来监视标志变量,而不是'while(1)'循环。

然后我决定让这件事情继续下去。但是在cocos2d-x框架中如何创建和销毁表面的细节仍然留给我研究。 :)