[gtk/wip/chergert/glproto: 805/920] handle degenerate assertions in nine slices




commit 8e3cf08c757736938f0a373fc80523d38a487cbb
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 28 21:34:03 2021 -0800

    handle degenerate assertions in nine slices
    
    if you are scaled way out, such as a paintable in the node-editor, you
    might have a degenerate case where the assertions would be 2 < 1. In
    general those cases don't matter so much because we are so far zoomed out.
    
    This way we can leave these on in debug builds rather than having them
    crash things.

 gsk/next/ninesliceprivate.h | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/gsk/next/ninesliceprivate.h b/gsk/next/ninesliceprivate.h
index d0f55545ed..404e626367 100644
--- a/gsk/next/ninesliceprivate.h
+++ b/gsk/next/ninesliceprivate.h
@@ -114,7 +114,13 @@ nine_slice_rounded_rect (GskGLTextureNineSlice *slices,
   slices[8].rect.height = bottom_height;
 
 #ifdef G_ENABLE_DEBUG
-  g_assert_cmpfloat (size->width, >=, left_width + right_width);
+  /* These only hold true when the values from ceilf() above
+   * are greater than one. Otherwise they fail, like will happen
+   * with the node editor viewing the textures zoomed out.
+   */
+  if (size->width > 1)
+    g_assert_cmpfloat (size->width, >=, left_width + right_width);
+  if (size->height > 1)
   g_assert_cmpfloat (size->height, >=, top_height + bottom_height);
 #endif
 }
@@ -277,7 +283,16 @@ nine_slice_grow (GskGLTextureNineSlice *slices,
 
   /* Rows don't overlap */
   for (guint i = 0; i < 3; i++)
-    g_assert_cmpint (slices[i * 3 + 0].rect.x + slices[i * 3 + 0].rect.width, <, slices[i * 3 + 1].rect.x);
+    {
+      int lhs = slices[i * 3 + 0].rect.x + slices[i * 3 + 0].rect.width;
+      int rhs = slices[i * 3 + 1].rect.x;
+
+      /* Ignore the case where we are scaled out and the
+       * positioning is degenerate, such as from node-editor.
+       */
+      if (rhs > 1)
+        g_assert_cmpint (lhs, <, rhs);
+    }
 #endif
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]