From 7dccad8d12811b20d63253083588431805223e37 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Sun, 30 Mar 2025 19:14:16 -0400 Subject: [PATCH] fix: prevent crash in game over animation by checking for zero blur radius --- .../main/java/com/mintris/game/GameView.kt | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/mintris/game/GameView.kt b/app/src/main/java/com/mintris/game/GameView.kt index 85a44a4..741b662 100644 --- a/app/src/main/java/com/mintris/game/GameView.kt +++ b/app/src/main/java/com/mintris/game/GameView.kt @@ -57,6 +57,15 @@ class GameView @JvmOverloads constructor( isAntiAlias = true } + private val borderGlowPaint = Paint().apply { + color = Color.WHITE + alpha = 60 + isAntiAlias = true + style = Paint.Style.STROKE + strokeWidth = 2f + maskFilter = BlurMaskFilter(8f, BlurMaskFilter.Blur.OUTER) + } + private val ghostBlockPaint = Paint().apply { color = Color.WHITE alpha = 80 // 30% opacity @@ -89,15 +98,6 @@ class GameView @JvmOverloads constructor( maskFilter = BlurMaskFilter(12f, BlurMaskFilter.Blur.OUTER) } - private val borderGlowPaint = Paint().apply { - color = Color.WHITE - alpha = 60 - isAntiAlias = true - style = Paint.Style.STROKE - strokeWidth = 2f - maskFilter = BlurMaskFilter(8f, BlurMaskFilter.Blur.OUTER) - } - // Add a new paint for the pulse effect private val pulsePaint = Paint().apply { color = Color.CYAN @@ -410,12 +410,6 @@ class GameView @JvmOverloads constructor( } override fun onDraw(canvas: Canvas) { - // Skip drawing if paused or game over - faster return - if (isPaused || gameBoard.isGameOver) { - super.onDraw(canvas) - return - } - // Set hardware layer type during draw for better performance val wasHardwareAccelerated = isHardwareAccelerated if (!wasHardwareAccelerated) { @@ -447,12 +441,28 @@ class GameView @JvmOverloads constructor( if (isGameOverAnimating) { val gameOverPaint = Paint().apply { color = Color.WHITE - alpha = (128 * gameOverAlpha).toInt() + alpha = (200 * gameOverAlpha).toInt() // Increased from 128 to 200 isAntiAlias = true style = Paint.Style.FILL - maskFilter = BlurMaskFilter(48f * gameOverAlpha, BlurMaskFilter.Blur.OUTER) + // Only apply blur if alpha is greater than 0 + if (gameOverAlpha > 0) { + maskFilter = BlurMaskFilter(64f * gameOverAlpha, BlurMaskFilter.Blur.OUTER) // Increased from 48f to 64f + } } canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), gameOverPaint) + + // Add a second layer for more intensity + val gameOverPaint2 = Paint().apply { + color = Color.WHITE + alpha = (100 * gameOverAlpha).toInt() + isAntiAlias = true + style = Paint.Style.FILL + // Only apply blur if alpha is greater than 0 + if (gameOverAlpha > 0) { + maskFilter = BlurMaskFilter(32f * gameOverAlpha, BlurMaskFilter.Blur.OUTER) + } + } + canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), gameOverPaint2) } } @@ -1163,8 +1173,8 @@ class GameView @JvmOverloads constructor( gameHaptics?.vibrateForGameOver() // Create new game over animation - gameOverAnimator = ValueAnimator.ofFloat(0f, 1f, 0.7f).apply { - duration = 1500L // 1.5 seconds total + gameOverAnimator = ValueAnimator.ofFloat(0f, 1f, 0.8f).apply { + duration = 1000L // 1 second total interpolator = LinearInterpolator() addUpdateListener { animation -> @@ -1177,7 +1187,7 @@ class GameView @JvmOverloads constructor( addListener(object : android.animation.AnimatorListenerAdapter() { override fun onAnimationEnd(animation: android.animation.Animator) { isGameOverAnimating = false - gameOverAlpha = 0.7f // Keep at 70% opacity + gameOverAlpha = 0.8f // Keep at 80% opacity invalidate() Log.d(TAG, "Game over animation ended") }