Horis пре 2 година
родитељ
комит
9d4bcbf091
1 измењених фајлова са 16 додато и 2 уклоњено
  1. 16 2
      app/src/main/java/io/legado/app/utils/PictureMirror.kt

+ 16 - 2
app/src/main/java/io/legado/app/utils/PictureMirror.kt

@@ -12,7 +12,7 @@ class PictureMirror {
 
 
     @Volatile
     @Volatile
     var isDirty = true
     var isDirty = true
-    val lock = ReentrantLock()
+    var lock: ReentrantLock? = null
 
 
     inline fun drawLocked(
     inline fun drawLocked(
         canvas: Canvas?,
         canvas: Canvas?,
@@ -21,8 +21,22 @@ class PictureMirror {
         block: Canvas.() -> Unit
         block: Canvas.() -> Unit
     ) {
     ) {
         if (atLeastApi23) {
         if (atLeastApi23) {
-            if (picture == null) picture = Picture()
+            if (picture == null) {
+                synchronized(this) {
+                    if (picture == null) {
+                        picture = Picture()
+                    }
+                }
+            }
+            if (lock == null) {
+                synchronized(this) {
+                    if (lock == null) {
+                        lock = ReentrantLock()
+                    }
+                }
+            }
             val picture = picture!!
             val picture = picture!!
+            val lock = lock!!
             if (isDirty) {
             if (isDirty) {
                 if (!lock.tryLock()) return
                 if (!lock.tryLock()) return
                 try {
                 try {