Error : RuntimeException at DisplayListCanvas.throwIfCannotDraw

前端 未结 4 2192
你的背包
你的背包 2021-02-18 13:55

My application work very well on nougat emulator and many devices, but i found this exception in google play crash reporter, I don\'t know why it happened, The exception causes

相关标签:
4条回答
  • 2021-02-18 14:33

    Just Resize your image in my case my Splash screen image dimensions are 1544x2100 so i changed to 1080x2100 and that will work!! Hope this will help!!! Thanks!!!

    0 讨论(0)
  • 2021-02-18 14:45

    Try to set a debug point in android.view.DisplayListCanvas.throwIfCannotDraw and check what image is throw an exception. Some of them is incorrect - large size or you have too many images for example and cant record to canvas pool.

    0 讨论(0)
  • 2021-02-18 14:49

    I had the exact same problem with Samsung Galaxy S6 S7 S8. In my case Splash Screen had high resolution and it was mistakenly placed in the drawable folder. I found solution from this answer.

    1. Right Click on drawable -> New -> Directory.
    2. Enter new directory name: xxhdpi. It will create a new folder named drawable-xxhdpi if you go to res
    3. Move your splash image from drawable to drawable-xxhdpi.
    0 讨论(0)
  •  private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
    
        @Override
        protected void throwIfCannotDraw(Bitmap bitmap) {
            super.throwIfCannotDraw(bitmap);
            int bitmapSize = bitmap.getByteCount();
            if (bitmapSize > MAX_BITMAP_SIZE) {
                throw new RuntimeException(
                        "Canvas: trying to draw too large(" + bitmapSize + "bytes) bitmap.");
            }
        }
    

    See this code in DisplayListCanvas,otherwise look at View#draw() method,

    boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) {
        boolean drawingWithRenderNode = mAttachInfo != null
                    && mAttachInfo.mHardwareAccelerated
                    && hardwareAcceleratedCanvas;
        ···
        if (drawingWithRenderNode) {
            // Delay getting the display list until animation-driven alpha values are
            // set up and possibly passed on to the view
            renderNode = updateDisplayListIfDirty();
            if (!renderNode.isValid()) {
                // Uncommon, but possible. If a view is removed from the hierarchy during the call
                // to getDisplayList(), the display list will be marked invalid and we should not
                // try to use it again.
                renderNode = null;
                drawingWithRenderNode = false;
                }
            }
        ···
    }
    

    that why we can resolve the problem by cancel the hardwareAccelerated

    0 讨论(0)
提交回复
热议问题