2012-01-22 18 views
6

Tôi gần như đã kết thúc với trò chơi của mình bây giờ, nhưng hôm nay tôi gặp phải một vấn đề anoying thực sự. Khi tôi bắt đầu trò chơi và chỉ đợi một vài giây, chương trình sẽ tự động tắt. Và tôi không có tiếng nổ nào.Whats lỗi trong logcat của tôi?

Đây là những gì logcat của tôi cho thấy:

01-22 16:20:31.232: DEBUG/szipinf(333): Initializing inflate state 
01-22 16:20:31.563: DEBUG/PhoneWindow(333): couldn't save which view has focus because the focused view [email protected] has no id. 
01-22 16:20:36.362: WARN/ActivityManager(73): Activity pause timeout for HistoryRecord{406532f8 com.JDL.Apps.Snake/.SnakeGame} 
01-22 16:20:43.682: INFO/ActivityManager(73): Start proc com.android.launcher for activity com.android.launcher/com.android.launcher2.Launcher: pid=358 uid=10026 gids={} 
01-22 16:21:20.393: ERROR/InputDispatcher(73): channel '406762c0 com.JDL.Apps.Snake/com.JDL.Apps.Snake.SnakeGame (server)' ~ Consumer closed input channel or an error occurred. events=0x8 
01-22 16:21:20.402: ERROR/InputDispatcher(73): channel '406762c0 com.JDL.Apps.Snake/com.JDL.Apps.Snake.SnakeGame (server)' ~ Channel is unrecoverably broken and will be disposed! 
01-22 16:21:21.092: INFO/WindowManager(73): WIN DEATH: Window{406762c0 com.JDL.Apps.Snake/com.JDL.Apps.Snake.SnakeGame paused=false} 
01-22 16:21:21.142: WARN/ActivityManager(73): Timeout of broadcast BroadcastRecord{40728640 android.intent.action.TIME_TICK} - [email protected]406300f8, started 56630ms ago 
01-22 16:21:21.142: WARN/ActivityManager(73): Receiver during timeout: BroadcastFilter{4062f930 ReceiverList{4062f8b8 73 system/1000 local:406300f8}} 
01-22 16:21:21.172: INFO/ActivityManager(73): Process com.JDL.Apps.Snake (pid 333) has died. 
01-22 16:21:21.362: INFO/WindowManager(73): WIN DEATH: Window{4072b188 SurfaceView paused=false} 
01-22 16:21:21.443: INFO/ActivityManager(73): Low Memory: No more background processes. 

Tôi có tiếc là không có code để chia sẻ vì tôi không biết là chương trình bị treo.

EDIT: Mã Vẽ:

@Override 
public void screen(float deltaTime) { 
    Graphics g = app.getGraphics(); 

    g.drawPixmap(Assets.background, 0, 0); 

    g.drawPixmap(Assets.facebook, 750, 20); 

    g.drawText("SNAKE", 10, 150, Color.BLACK, 150, AndroidGraphics.LEFT, 
      null, 0); 
    g.drawText("START", g.getWidth()/2, g.getHeight() - 20, Color.BLACK, 
      120, AndroidGraphics.CENTER, startRec, 0); 
    g.drawText("HIGHSCORE", 20, 275, Color.BLACK, 50, AndroidGraphics.LEFT, 
      highRec, 0); 
    g.drawText("MORE APPS", g.getWidth() - 20, 275, Color.BLACK, 50, 
      AndroidGraphics.RIGHT, moreRec, 0); 
    if (Settings.soundEnabled) 
     g.drawPixmap(Assets.buttons, new Rect(0, 0, 100, 100), new Rect(0, 
       380, 100, 480)); 
    else 
     g.drawPixmap(Assets.buttons, new Rect(100, 0, 200, 100), new Rect(
       0, 380, 100, 480)); 
} 

drawText phương pháp:

@Override 
public void drawText(String text, int x, int y, int color, int size, 
     int position, Rect bounds, int rotation) { 
    if (position == LEFT) 
     paint.setTextAlign(Paint.Align.LEFT); 
    else if (position == CENTER) 
     paint.setTextAlign(Paint.Align.CENTER); 
    else if (position == RIGHT) 
     paint.setTextAlign(Paint.Align.RIGHT); 
    else 
     return; 
    paint.setColor(color); 
    Typeface typeface = Typeface.createFromAsset(assets, "typewrite.TTF"); 
    paint.setTypeface(typeface); 
    paint.setTextSize(size); 
    if (bounds != null) { 
     Rect rec = new Rect(); 
     paint.getTextBounds(text, 0, text.length(), rec); 
     bounds.bottom = y; 
     bounds.top = y - rec.height(); 
     if (position == CENTER) { 
      bounds.left = x - rec.width()/2; 
      bounds.right = x + rec.width()/2; 
     } else if (position == RIGHT) { 
      bounds.left = x - rec.width(); 
      bounds.right = x; 
     } else if (position == LEFT) { 
      bounds.left = x; 
      bounds.right = x + rec.width(); 
     } else 
      return; 
    } 
    canvas.save(); 
    canvas.rotate(rotation, x, y); 
    canvas.drawText(text, x, y, paint); 
    canvas.restore(); 
} 
+0

Rò rỉ bộ nhớ không có trong mã vẽ của bạn. Một nơi có thể xem là trong vòng đời [activity lifecycle] của bạn (http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle). Các nhật ký dường như chỉ ra rằng bạn đang sử dụng kiến ​​trúc máy khách/máy chủ; một số khác có thể nằm trong IPC hoặc mã mạng của bạn. –

+0

Bạn có chắc chắn không? Khi tôi loại bỏ phương thức drawText(), chương trình hiện bị lỗi. – Daniel

+2

Hmm. Thử tải phông chữ của bạn một lần khi chương trình bắt đầu thay vì mỗi khi bạn vẽ văn bản. –

Trả lời

10

Bạn bị rò rỉ bộ nhớ ở đâu đó. Xem this blog post trong tài liệu dành cho nhà phát triển cho các công cụ mà bạn có thể sử dụng để theo dõi nó. Đồng thời xem this blog post để biết các mẹo lập trình để tránh rò rỉ bộ nhớ trong các ứng dụng Android.

3
~ Channel is unrecoverably broken and will be disposed! 

01-22 16:21:21.443: INFO/ActivityManager(73): Low Memory: No more background processes. 

Có vẻ như trò chơi của bạn sử dụng hai dung lượng bộ nhớ (hoặc) rò rỉ bộ nhớ. Bạn có thể cần phải đăng nhập sử dụng bộ nhớ của quá trình của bạn bằng cách sử dụng một số kỹ thuật được mô tả trong các cuộc thảo luận this và lấy từ đó.

+0

Nhưng làm thế nào có thể khi tôi chỉ vẽ một số văn bản và nền một màu? Điều đó không nên mất nhiều bộ nhớ. Tôi nên làm gì? – Daniel

+2

@Daniel - nếu mã của bạn đơn giản như bạn mô tả, hãy đăng toàn bộ và chúng tôi có thể xem nó có thể bị rò rỉ ở đâu. –

+0

Tôi đã thực hiện nó ngay bây giờ .. – Daniel

1

Với gỡ lỗi một bước, tôi gặp lỗi chi tiết: bạn phải cung cấp thuộc tính layout_height trong .... Nó đã hoạt động cho trường hợp của tôi.

Các vấn đề liên quan