Android游戏开发E / JavaBinder:失败的绑定交易

时间:2018-11-17 22:26:18

标签: java android multithreading google-play-games game-loop

如何处理E / JavaBinder:失败的BINDER交易导致应用程序崩溃?

我正在使用SurfaceView制作Android游戏。

我还在无限循环本身使用专用线程,其中既包含update()方法,又包含draw()方法。

update()方法更新字符position(logic)和sprite,而draw()方法绘制到画布。

专用线程同时处理update()和draw(),因为它们需要同步。

onTouchEvent(用户点击)由主线程处理。

尽管我不能确定,但​​我怀疑出现此错误: E / JavaBinder:!!!绑定交易失败,因为 draw()方法和update()方法都调用其他方法,这些方法又调用其他方法,依此类推..导致几乎是递归的行为。

例如我的update()方法,调用characterOne.update()..然后调用characterOneSpells.update(),然后调用spellOne.update(),依此类推...对于draw()来说是相同的。我怀疑这会溢出绑定缓冲区或类似的内容。.我不确定..所有这些都在无限循环中无限次发生。

请注意,我采用这种方法(方法称为调用其他方法的方法),因为在逻辑上我认为角色应该负责绘制自己,而咒语应该负责绘制自身,而不是角色负责绘制和更新咒语等。对我来说,每个对象都应负责绘制和更新自身,那就是我的推理,我可能错了,请让我知道您的想法。

现在,我是游戏制作的新手,而实际上这是我的第一款游戏,所以请放轻松,我正在尝试学习!

我的代码示例和错误日志可以在下面找到。

对为什么我得到这个 E / JavaBinder的任何见解:!!!绑定交易失败!,以及如何解决该问题,将不胜感激!也要随时提出更好的设计或方法,因为我正在尝试学习。

谢谢!

我用**重要**注释标记了代码的重要部分,使事情变得更容易。

错误日志:

    11-17 17:07:30.132 934-1460/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
11-17 17:07:30.388 1451-1451/? E/RecyclerView: No adapter attached; skipping layout
11-17 17:07:32.328 934-992/? E/InputDispatcher: channel '329e61e3 com.amazon.firelauncher/com.amazon.firelauncher.Launcher (server)' ~ Channel is unrecoverably broken and will be disposed!
11-17 17:07:32.407 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.442 934-1011/? E/WifiService: Multicaster binderDied
11-17 17:07:32.462 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.464 146-146/? E/lowmemorykiller: Error opening /proc/2493/oom_score_adj; errno=2
11-17 17:07:32.464 146-146/? E/lowmemorykiller: Error opening /proc/1217/oom_score_adj; errno=2
11-17 17:07:36.426 6868-6868/? E/cr_AWVDeploymentClient: Chromium Version = v59 key doesn't exist. So, default version config will be used.
11-17 17:07:36.428 6868-6868/? E/cr_AWVDeploymentClient: Default device config doesn't exist
11-17 17:07:39.313 934-992/? E/InputDispatcher: channel '11e88fc0 info.evyatar.mystrategygame/info.evyatar.mystrategygame.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
11-17 17:07:40.905 7010-7051/? E/SQLiteLog: (283) recovered 44 frames from WAL file /data/user/0/com.amazon.firelauncher/databases/producer.db-wal
11-17 17:07:41.091 7010-7059/? E/SQLiteLog: (283) recovered 90 frames from WAL file /data/user/0/com.amazon.firelauncher/databases/CardDeviceAgentDB-wal
11-17 17:07:43.558 7010-7010/? E/RecyclerView: No adapter attached; skipping layout
11-17 17:07:43.622 7089-7089/? E/TimeoutManagerClient: bindService() Failed to bind to ECService
11-17 17:07:43.631 7165-7165/? E/Dagger2: ApplicationModule context already set
11-17 17:07:44.924 7089-7311/? E/...iceDataCommunication: Got a RemoteMAPException
                                                          com.amazon.identity.auth.device.framework.RemoteMAPException: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key ke_device was not found in the device data store. This device does not support ke_device. This error is expected if the device not support ke_device.
                                                              at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:118)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataStoreSystemPropertyDecorator.getValue(DeviceDataStoreSystemPropertyDecorator.java:52)
                                                              at com.amazon.identity.auth.device.api.DeviceDataStore.getValue(DeviceDataStore.java:96)
                                                              at com.amazon.avod.identity.DeviceProperties.isKidsEditionDevice(DeviceProperties.java:374)
                                                              at com.amazon.avod.identity.DeviceProperties.initialize(DeviceProperties.java:201)
                                                              at com.amazon.avod.core.ApplicationComponents$InitializeDeviceProperties.initialize(ApplicationComponents.java:543)
                                                              at com.amazon.avod.core.ApplicationComponents$InitializeRunnable.run(ApplicationComponents.java:787)
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                              at java.lang.Thread.run(Thread.java:818)
                                                           Caused by: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key ke_device was not found in the device data store. This device does not support ke_device. This error is expected if the device not support ke_device.
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:93)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:61)
                                                              at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:112)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59) 
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52) 
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataStoreSystemPropertyDecorator.getValue(DeviceDataStoreSystemPropertyDecorator.java:52) 
                                                              at com.amazon.identity.auth.device.api.DeviceDataStore.getValue(DeviceDataStore.java:96) 
                                                              at com.amazon.avod.identity.DeviceProperties.isKidsEditionDevice(DeviceProperties.java:374) 
                                                              at com.amazon.avod.identity.DeviceProperties.initialize(DeviceProperties.java:201) 
                                                              at com.amazon.avod.core.ApplicationComponents$InitializeDeviceProperties.initialize(ApplicationComponents.java:543) 
                                                              at com.amazon.avod.core.ApplicationComponents$InitializeRunnable.run(ApplicationComponents.java:787) 
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                              at java.lang.Thread.run(Thread.java:818) 
11-17 17:07:45.701 7010-7085/? E/...iceDataCommunication: Got a RemoteMAPException
                                                          com.amazon.identity.auth.device.framework.RemoteMAPException: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key re_device was not found in the device data store. This device does not support re_device. This error is expected if the device not support re_device.
                                                              at com.amazon.identity.auth.device.framework.SecureContentResolver.acquireContentProviderClient(SecureContentResolver.java:118)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.retriveValueFromCentralStore(DeviceDataCommunication.java:59)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication.getValue(DeviceDataCommunication.java:52
                                                              at java.lang.Thread.run(Thread.java:818)
                                                           Caused by: com.amazon.identity.auth.device.api.DeviceDataStoreException: Key re_device was not found in the device data store. This device does not support re_device. This error is expected if the device not support re_device.
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:93)
                                                              at com.amazon.identity.auth.device.devicedata.DeviceDataCommunication$1.useContentProviderClient(DeviceDataCommunication.java:61)

                                                              at com.amazon.firelauncher.services.MapCache.updateDeviceData(MapCache.java:579) 
                                                              at com.amazon.firelauncher.services.MapCache.access$700(MapCache.java:47) 
                                                              at com.amazon.firelauncher.services.MapCache$3.run(MapCache.java:491) 
                                                              at com.amazon.firelauncher.services.BackgroundExecutor$InternalRunnable.run(BackgroundExecutor.java:180) 
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                              at java.lang.Thread.run(Thread.java:818) 
11-17 17:07:45.930 7343-7343/? E/SQLiteLog: (283) recovered 120 frames from WAL file /data/securedStorageLocation/com.amazon.providers.contentsupport/contentsupport.db-wal
11-17 17:07:45.979 7343-7343/? E/SQLiteLog: (284) automatic index on languages(packageId)
11-17 17:07:46.007 7343-7343/? E/SQLiteLog: (284) automatic index on languages(packageId)
11-17 17:07:47.386 7010-7417/? E/F_C.ArcusRemoteConfigur: No valid offline remote setting found for the current device, not setting default
                                                          java.lang.Exception: Error getting the baseline setting for Arcus config cms
                                                              at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:106)

                                                              at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                              at android.os.Looper.loop(Looper.java:135)
                                                              at android.os.HandlerThread.run(HandlerThread.java:61)
                                                           Caused by: java.lang.Exception: Exception reading from cms/baseline.json
                                                              at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:43)
                                                              at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:14)
                                                              at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:88)
                                                              at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:22) 
                                                              at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration$1.map(ArcusRemoteConfiguration.java:67) 
                                                              at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration$1.map(ArcusRemoteConfiguration.java:60) 
                                                              at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration.initialize(ArcusRemoteConfiguration.java:117) 
                                                              at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111) 
                                                              at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57) 
                                                              at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                              at android.os.Looper.loop(Looper.java:135) 
                                                              at android.os.HandlerThread.run(HandlerThread.java:61) 
                                                           Caused by: java.io.FileNotFoundException: cms/baseline.json
                                                              at android.content.res.AssetManager.openAsset(Native Method)
                                                              at android.content.res.AssetManager.open(AssetManager.java:313)
                                                              at android.content.res.AssetManager.open(AssetManager.java:287)
                                                              at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:29)
                                                              at com.amazon.firelauncher.reccardproducer.settings.JSONFile.value(JSONFile.java:14) 
                                                              at com.amazon.firelauncher.reccardproducer.settings.OfflineSetting.value(OfflineSetting.java:88) 

                                                              at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111) 
                                                              at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57) 
                                                              at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                              at android.os.Looper.loop(Looper.java:135) 
                                                              at android.os.HandlerThread.run(HandlerThread.java:61) 
11-17 17:07:47.400 7010-7417/? E/F_C.FireDeviceAttribute: BuildNumber is not a valid String attribute (wrong type: Integer)
11-17 17:07:47.416 7010-7417/? E/F_C.ArcusParameters: Exception getting attribute %s, no attribute added
                                                      java.lang.NullPointerException: attrValue cannot be null
                                                          at com.amazonaws.mobileconnectors.remoteconfiguration.internal.gear.Checks.checkNotNull(Checks.java:20)
                                                          at com.amazonaws.mobileconnectors.remoteconfiguration.internal.AttributesImpl.addAttributePrivate(AttributesImpl.java:193)
                                                          at com.amazonaws.mobileconnectors.remoteconfiguration.internal.AttributesImpl.addAttribute(AttributesImpl.java:103)
                                                          at com.amazon.firelauncher.reccardproducer.arcus.ArcusParameters.decorateManager(ArcusParameters.java:87)
                                                          at com.amazon.firelauncher.reccardproducer.arcus.ArcusRemoteConfiguration.initialize(ArcusRemoteConfiguration.java:119)
                                                          at com.amazon.firelauncher.reccardproducer.cards.RecommendationsController.getInstance(RecommendationsController.java:111)
                                                          at com.amazon.firelauncher.reccardproducer.ProducerService.onHandleIntent(ProducerService.java:57)
                                                          at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                          at android.os.Looper.loop(Looper.java:135)
                                                          at android.os.HandlerThread.run(HandlerThread.java:61)

示例代码

        public class GameLoop extends SurfaceView implements SurfaceHolder.Callback {

    private Context myContext;
    private SurfaceHolder mySurfaceHolder;
    private Bitmap backgroundImg;
    private int screenW = 1;
    private int screenH = 1;
    private boolean running = false;
    private boolean onTitleScreen = true;
    private GameLoopThread thread;
    private int backgroundOrigW;
    private int backgroundOrigH;
    private float scaleW;
    private float scaleH;
    private float drawScaleW;
    private float drawScaleH;
    private int fingerX, fingerY;
    private boolean isDragging = false;
    SingltonAssetsObject mSingltonAssetsObject;
    private boolean gameOver;
    Point userClickPoint;

    //Characters
    CharacterTypeOne characterFighterOne,characterFighterTwo,characterFighterThree;
    CharacterTypeTwo CharacterMage;

    public GameLoop(Context context, AttributeSet attrs) {
        super(context, attrs);
        SurfaceHolder holder = getHolder();
        holder.addCallback(this);

        //init clickRectangle
        userClickPoint = new Point();

        //creates the gameLoop thread DRAW THREAD
        thread = new GameLoopThread(holder,context);
        setFocusable(true);


    }


    public void initCharacters(){
        mSingltonAssetsObject = SingltonAssetsObject.getInstance(myContext,scaleW,scaleH);

        characterFighterOne = new characterFighterOne(myContext,1000,1,150,350,100,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
        characterFighterTwo = new characterFighterOne(myContext,1001,67,350,350,100,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);
        characterFighterThree =  new characterFighterOne(myContext,1002,99,550,350,1000,15,1.0,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);

        characterMage = new characterMage(myContext,50,28,650,250,100,15,0.1,scaleW,scaleH,drawScaleW,drawScaleH,screenW,screenH);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return thread.doTouchEvent(event);
    }
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        thread.setSurfaceSize(width, height);
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        thread.setRunning(true);
        if (thread.getState() == Thread.State.NEW) {
            thread.start();
        }
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        thread.setRunning(false);
    }


    class GameLoopThread extends Thread{

        public GameLoopThread(SurfaceHolder surfaceHolder, Context context){
            //initialzied in inner class and not outter because this variable will act as a lock and will be shard with all threads
            mySurfaceHolder = surfaceHolder;
            myContext = context;
            //the background image of the title screen
            backgroundImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.title);
            backgroundOrigW = backgroundImg.getWidth();
            backgroundOrigH = backgroundImg.getHeight();
        }
        //This method is the main game loop
        public  void run() {

            while (running) {

                    try { //lock canvas for drawing
                        c = mySurfaceHolder.lockCanvas(null);
                        synchronized (mySurfaceHolder) {
                            if (!gameOver)
                            {    
                                //** important ***
                                updateAnimationsAndPosition();
                            }

                            // **important **
                            draw(c);
                        }
                    } finally {
                        if (c != null) { //unlock canvas
                            mySurfaceHolder.unlockCanvasAndPost(c);
                        }
                    }
                } //while loop ends            
        } //run Method ends (gameLOOP)


        //This method will draw everything to the screen
        public void draw(Canvas canvas){
                canvas.drawBitmap(backgroundImg, 0, 0, null);
                if (!onTitleScreen) {
                          /* **Important**
                          Note: characterFighterOne.draw(canvas) calls spells.draw(canvas) 
                          which calls spellOne.draw(canvas).. which call spellIndicartor.draw(canvas) 
                          and so on... might be cauing the isssue?*/
                         characterFighterOne.draw(canvas);
                         characterFighterTwo.draw(canvas);
                         characterFighterThree.draw(canvas);
                         characterMage.draw(canvas);
                }
        }

        //This method updates the animations, for example changes image  every tick
        public void updateAnimationsAndPosition(){

            if(!onTitleScreen){
             /***Important**
                Note: characterFighterOne.updateAnimationsAndPosition() calls spells.update() 
                which calls spellOne.update().. which call spellIndicartor.update() 
                and so on... might be causing the issue?*/

                characterFighterOne.updateAnimationsAndPosition();  
                characterFighterTwo.updateAnimationsAndPosition();
                characterFighterThree.updateAnimationsAndPosition();
                characterMage.updateAnimationsAndPosition();
            }
        }

        public void setSurfaceSize(int width, int height) {
            synchronized (mySurfaceHolder) {
                screenW = width;
                screenH = height;
                backgroundImg = Bitmap.createScaledBitmap(backgroundImg, width, height, true);
                drawScaleW = (float) screenW / 960; //screen/background width image
                drawScaleH = (float) screenH / 640;


            }
        }
        //This method is in charge of user input ( clicks on screen, and how to respond to them)
        public boolean doTouchEvent(MotionEvent event){
            if(!onTitleScreen){
                characterFighterOne.doTouchEvent(event);
                characterFighterTwo.doTouchEvent(event);
                characterFighterThree.doTouchEvent(event);
                characterMage.doTouchEvent(event);
                userClickPoint.set((int)event.getX(),(int)event.getY());
            }
            synchronized (mySurfaceHolder) {
                int eventaction = event.getAction();
                int X = (int)event.getX();
                int Y = (int)event.getY();

                switch (eventaction ) {

                    case MotionEvent.ACTION_DOWN:
                        if(!gameOver){
                            fingerX = X;
                            fingerY = Y;
                            if (!onTitleScreen) {

                            }
                        }
                        break;
                    case MotionEvent.ACTION_MOVE:// used for dragging purposes
                        break;
                    case MotionEvent.ACTION_UP:
                        //Here I load all the images to memory ( while on the titleScreen normal size & scaled, find a better place, maybe OnCreate, leave for now)
                        if (onTitleScreen) {
                            backgroundImg = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.background);
                            backgroundImg = Bitmap.createScaledBitmap(backgroundImg, screenW, screenH, true);
                            onTitleScreen = false;
                            scaleW = (float) screenW/ (float) backgroundOrigW;
                            scaleH = (float) screenH/ (float) backgroundOrigH;
                            initCharacters();
                        }
                        if (gameOver) {
                            gameOver = false;
                        }
                        break;
                } 
            } 
            return true;
        } 

        //This method enables and disables the Thread
        public void setRunning(boolean b) {
        running = b;
    }


    } 

} 

0 个答案:

没有答案