Browse Source

Fix: scene recycler actor bitmap exception

liweihao 6 years ago
parent
commit
635eaff477
1 changed files with 4 additions and 3 deletions
  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)