changeset 1612:228a41233540

fix software rendering if empty target canvas
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Oct 2020 18:27:06 +0100
parents 787db80a5a1b
children 5f0660fe06c3
files Applications/Platforms/WebAssembly/WebAssemblyCairoViewport.cpp
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Platforms/WebAssembly/WebAssemblyCairoViewport.cpp	Thu Oct 29 18:02:03 2020 +0100
+++ b/Applications/Platforms/WebAssembly/WebAssemblyCairoViewport.cpp	Thu Oct 29 18:27:06 2020 +0100
@@ -77,18 +77,22 @@
       }
     }
 
-    // Execute JavaScript commands to blit the image buffer onto the
-    // 2D drawing context of the HTML5 canvas
-    EM_ASM({
-        const data = new Uint8ClampedArray(Module.HEAP8.buffer, $1, 4 * $2 * $3);
-        const img = new ImageData(data, $2, $3);
-        const ctx = document.getElementById(UTF8ToString($0)).getContext('2d');
-        ctx.putImageData(img, 0, 0);
-      },
-      GetCanvasId().c_str(), // $0
-      javascript_->GetBuffer(),   // $1
-      javascript_->GetWidth(),    // $2
-      javascript_->GetHeight());  // $3
+    if (width != 0 &&
+        height != 0)
+    {
+      // Execute JavaScript commands to blit the image buffer onto the
+      // 2D drawing context of the HTML5 canvas
+      EM_ASM({
+          const data = new Uint8ClampedArray(Module.HEAP8.buffer, $1, 4 * $2 * $3);
+          const img = new ImageData(data, $2, $3);
+          const ctx = document.getElementById(UTF8ToString($0)).getContext('2d');
+          ctx.putImageData(img, 0, 0);
+        },
+        GetCanvasId().c_str(),      // $0
+        javascript_->GetBuffer(),   // $1
+        javascript_->GetWidth(),    // $2
+        javascript_->GetHeight());  // $3
+    }
   }