Explorar o código

Fix: scene recycler actor bitmap exception

liweihao %!s(int64=6) %!d(string=hai) anos
pai
achega
635eaff477
Modificáronse 1 ficheiros con 4 adicións e 3 borrados
  1. 4 3
      src/main/java/com/bomostory/sceneeditmodule/SceneDrawer.kt

+ 4 - 3
src/main/java/com/bomostory/sceneeditmodule/SceneDrawer.kt

@@ -10,7 +10,6 @@ import com.bomostory.sceneeditmodule.basicdata.Scene
 import kotlin.math.pow
 
 object SceneDrawer {
-    lateinit var actorBitmap: Bitmap
     fun drawScene(context: Context, scene: Scene, trackX: Int, scaleWidth: Int, scaleHeight: Int): Bitmap? {
         var sceneBitmap: Bitmap? = null
 
@@ -22,7 +21,7 @@ object SceneDrawer {
             for (layer in layers) {
                 for (actor in layer.actors) {
                     if (!actor.isDialogue) {
-                        actorBitmap = BitmapFactory.decodeFile(actor.resourcePath)
+                        var actorBitmap = BitmapFactory.decodeFile(actor.resourcePath)
                         actorBitmap = Bitmap.createScaledBitmap(actorBitmap, actor.sideLength, actor.sideHeight, true)
 
                         canvas.save()
@@ -30,7 +29,9 @@ object SceneDrawer {
                         canvas.drawBitmap(actorBitmap, actor.positionX.toFloat(), actor.positionY.toFloat(), Paint())
                         canvas.restore()
 
-                        actorBitmap.recycle()
+                        if (!actorBitmap.isRecycled) {
+                            actorBitmap.recycle()
+                        }
                     } else {
                         canvas.save()
                         canvas.translate(trackX / 2f.pow(layers.indexOf(layer)), 0f)