about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-21 00:37:17 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-21 00:41:26 +0200
commit1369135f9719ebe7a58c75fd73ecbfec92ef7e24 (patch)
treeaf9ee62f2138651618d206853bec4fe49dfd6e14
parentf60f8010604c227d13e1d953f1565d4d54174416 (diff)
downloadchawan-1369135f9719ebe7a58c75fd73ecbfec92ef7e24.tar.gz
dom: fix race condition in image loading
We were not setting the invalid flag on bitmap load, so any incremental
reshape could interfere with displaying images that got loaded after
the reshape.
-rw-r--r--src/html/dom.nim7
-rw-r--r--todo2
2 files changed, 4 insertions, 5 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 123296f5..2cee89ac 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -3023,11 +3023,11 @@ proc loadResource(window: Window; image: HTMLImageElement) =
     let p = window.loader.fetch(newRequest(url)).then(
       proc(res: JSResult[Response]): EmptyPromise =
         if res.isNone:
-          return
+          return newResolvedPromise()
         let response = res.get
         let contentType = response.getContentType("image/x-unknown")
         if contentType.until('/') != "image":
-          return
+          return newResolvedPromise()
         let cacheId = window.loader.addCacheFile(response.outputId,
           window.loader.clientPid)
         let request = newRequest(
@@ -3053,7 +3053,7 @@ proc loadResource(window: Window; image: HTMLImageElement) =
               break
         cachedURL.loading = false
         cachedURL.expiry = expiry
-        return r.then(proc(res: JSResult[Response]): EmptyPromise =
+        return r.then(proc(res: JSResult[Response]) =
           if res.isNone:
             return
           let response = res.get
@@ -3082,6 +3082,7 @@ proc loadResource(window: Window; image: HTMLImageElement) =
           cachedURL.bmp = bmp
           for share in cachedURL.shared:
             share.bitmap = bmp
+          image.invalid = true
         )
       )
     window.loadingResourcePromises.add(p)
diff --git a/todo b/todo
index 9c2d3de7..1c924ee4 100644
--- a/todo
+++ b/todo
@@ -73,8 +73,6 @@ layout engine:
 images:
 - more efficient sixel display (store encoded images)
 - proper sixel color register allocation, dithering
-- fix race condition where images decoded after buffer load won't display until
-  reshape
 - incremental decoding, interlaced images, animation
 man:
 - add a DOM -> man page converter so that we do not depend on pandoc