Skip to content

Commit

Permalink
fix: 终极方案防止闪退
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 11, 2023
1 parent ec29c7e commit 774445d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) :
lateinit var images: ImageManager
private val logicThread = Thread {
try {
while (!Thread.interrupted() && !this.isStopped) {
synchronized(holder) {
while (!this.isStopped) {
synchronized(this.holder) {
update()
draw()
Thread.sleep(this.refreshInterval.toLong())
Expand Down Expand Up @@ -313,7 +313,9 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) :
paintLife(canvas)
// 绘制得分
paintScore(canvas)
this.holder.unlockCanvasAndPost(canvas)
if (this.holder.surface.isValid) {
this.holder.unlockCanvasAndPost(canvas)
}
}
}

0 comments on commit 774445d

Please sign in to comment.