3

My game windows are all floating PopupWindows

backpackPopupWindow = new PopupWindow(backpackView, width, height, focusable);

Some of my users reported after 30 minutes or so it will randomly crash with no information in my game's log file. I was able to get it to reproduce on a friend's Galaxy S8 phone and here is what I see in the log. First two lines below are from my game's logs (receiving information about the player's backpack from the server). A google for TooManySurfacesException returns 8 results :(

2020-07-22 22:45:58.703 27227-27227/com.kisnardonline.kisnardonline I/BitmapStore: BitmapStore: BitmapStore: First load: res/images/item/item_mouse_tail.png
2020-07-22 22:45:58.734 27227-27525/com.kisnardonline.kisnardonline I/MyCommandReceiver: Promage-backpackWindow@40-37-32|I|Gold|Shiny little coins.|coins.png...
2020-07-22 22:45:58.737 697-697/? E/SurfaceFlinger: createLayer() failed, already application created very many surfaces [PopupWindow:5659ba6[27227]]
2020-07-22 22:45:58.739 1411-4256/? E/SurfaceComposerClient: SurfaceComposerClient::createSurface error Broken pipe
2020-07-22 22:45:58.739 1411-4256/? E/SurfaceControl: @!@! Throw TooManySurfacesException [PopupWindow:5659ba6[27227]]
2020-07-22 22:45:58.742 1411-4256/? E/WindowManager: A process tried to create too many surfaces
    android.view.WindowManager$TooManySurfacesException
        at android.view.SurfaceControl.nativeCreate(Native Method)
        at android.view.SurfaceControl.<init>(SurfaceControl.java:704)
        at android.view.SurfaceControl.<init>(SurfaceControl.java:72)
        at android.view.SurfaceControl$Builder.build(SurfaceControl.java:456)
        at com.android.server.wm.WindowSurfaceController.<init>(WindowSurfaceController.java:141)
        at com.android.server.wm.WindowStateAnimator.createSurfaceLocked(WindowStateAnimator.java:632)
        at com.android.server.wm.WindowManagerService.createSurfaceControl(WindowManagerService.java:2779)
        at com.android.server.wm.WindowManagerService.relayoutWindow(WindowManagerService.java:2465)
        at com.android.server.wm.Session.relayoutForTranslate(Session.java:302)
        at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:518)
        at com.android.server.wm.Session.onTransact(Session.java:186)
        at android.os.Binder.execTransact(Binder.java:739)
2020-07-22 22:45:58.742 1411-4256/? I/Process: Sending signal. PID: 27227 SIG: 9

The second line where the backpack window information is received will "repaint" or "show" the player's backpack:

if (GameActivity.askedForBackpack || BackpackPanel.isViewVisible){
    if (BackpackPanel.isViewVisible) {
        GameActivity.backpackPanel.RepaintBackpack();
    } else {
        GameActivity.backpackPanel.ShowPopupBackpack(GameActivity.gameActivityRelativeLayout);
    }
    BackpackPanel.isViewVisible = true;
    GameActivity.askedForBackpack = false;
}

RepaintBackpack() loops through the data from server and updates the ImageViews (myImage):

if (BackpackPanel.backpackHolderFilename[ii].endsWith(".png")){
    myImage.setImageBitmap(BitmapStore.get().getBitmap(BackpackPanel.backpackHolderFilename[ii]));
} else if (BackpackPanel.backpackHolderFilename[ii].endsWith(".gif")){
    GlideApp.with(MyCommandReceiver.GetActiveActivity())
            .load(new File(Environment.getExternalStorageDirectory() + "/KisnardOnline/" + BackpackPanel.backpackHolderFilename[ii]))
            .override(ScreenUtils.getDPFromPixels(32), ScreenUtils.getDPFromPixels(32))
            .into(myImage);
} else if (BackpackPanel.backpackHolderFilename[ii].equals("")){
    myImage.setImageResource(android.R.color.transparent);
}

ShowPopupBackpack() creates the backpack PopupWindow and sets click listeners, etc:

// inflate the layout of the popup window
backpackView = MyCommandReceiver.GetLayoutInflater().inflate(R.layout.window_backpack, null);

// create the popup window
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = false; // do not let taps outside the popup also dismiss it
backpackPopupWindow = new PopupWindow(backpackView, width, height, focusable);
backpackPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
backpackPopupWindow.setOutsideTouchable(false);

Here is what the game (with backpack showing) looks like:

[screenshot of KisnardOnline backpack PopupWindow1

KisnardOnline
  • 653
  • 4
  • 16
  • 42

0 Answers0