changeset 1336:5ca89802a746

did: improve error messages
author sam <sam@basx.dev>
date Sat, 24 Aug 2024 12:33:46 +0700
parents f2ff6f624932
children 164276e8697f
files semicongine/image.nim semicongine/rendering/renderer.nim semicongine/rendering/shaders.nim
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/image.nim	Thu Aug 22 22:31:05 2024 +0700
+++ b/semicongine/image.nim	Sat Aug 24 12:33:46 2024 +0700
@@ -1,4 +1,5 @@
 import std/os
+import std/typetraits
 import std/streams
 import std/strutils
 
@@ -49,6 +50,13 @@
 
 proc `=copy`[S, T](dest: var ImageObject[S, T], source: ImageObject[S, T]) {.error.}
 
+func `$`*[S, IsArray](img: ImageObject[S, IsArray]): string =
+  let pixelTypeName = S.name
+  if IsArray == false:
+    &"{img.width}x{img.height} {pixelTypeName}"
+  else:
+    &"{img.width}x{img.height}[{img.nLayers}] {pixelTypeName}"
+
 func copy*[S, T](img: ImageObject[S, T]): ImageObject[S, T] =
   for bf, rf in fields(img, result):
     rf = bf
--- a/semicongine/rendering/renderer.nim	Thu Aug 22 22:31:05 2024 +0700
+++ b/semicongine/rendering/renderer.nim	Sat Aug 24 12:33:46 2024 +0700
@@ -618,8 +618,7 @@
           assert typeof(meshAttrValue) is GPUArray,
             "Mesh attribute '" & attrName & "' must be a GPUArray"
           assert typeof(attrValue) is elementType(meshAttrValue.data),
-            "Type of shader attribute and mesh attribute '" & attrName &
-              "' is not the same"
+            "Type of shader attribute and mesh attribute '" & attrName & "' is not the same (" & typeof(attrValue).name & " and " & elementType(meshAttrValue.data).name & ")"
           foundAttr = true
       assert foundAttr,
         "Attribute '" & attrName & "' is not provided in mesh type '" & name(TMesh) & "'"
--- a/semicongine/rendering/shaders.nim	Thu Aug 22 22:31:05 2024 +0700
+++ b/semicongine/rendering/shaders.nim	Sat Aug 24 12:33:46 2024 +0700
@@ -249,9 +249,9 @@
     elif hasCustomPragma(value, DescriptorSet):
       let setIndex = value.getCustomPragmaVal(DescriptorSet)
       assert not sawDescriptorSets[setIndex],
-        "Only one DescriptorSet per index is allowed per shader"
+        TShader.name & ": Only one DescriptorSet per index is allowed per shader"
       assert typeof(value) is object,
-        "Descriptor field '" & fieldname & "' must be of type object"
+        TShader.name & "Descriptor field '" & fieldname & "' must be of type object"
       assert setIndex < MAX_DESCRIPTORSETS,
         typetraits.name(TShader) & ": maximum " & $MAX_DESCRIPTORSETS &
           " descriptor sets allowed"