Mercurial > games > semicongine
changeset 819:4c8bab2d1cc5
add: some not-null assertions
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 23 Sep 2023 23:05:22 +0700 |
parents | 2fb719f13a98 |
children | 85470ae0f728 |
files | src/semicongine/scene.nim |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/scene.nim Sat Sep 23 22:10:33 2023 +0700 +++ b/src/semicongine/scene.nim Sat Sep 23 23:05:22 2023 +0700 @@ -17,11 +17,18 @@ scene.meshes.add tmp proc add*(scene: var Scene, mesh: Mesh) = + assert not mesh.isNil, "Cannot add a mesh that is 'nil'" scene.meshes.add mesh # generic way to add objects that have a mesh-attribute proc add*[T](scene: var Scene, obj: T) = - scene.meshes.add obj.mesh + for name, value in obj.fieldPairs: + when typeof(value) is Mesh: + assert not value.isNil, &"Cannot add a mesh that is 'nil': " & name + scene.meshes.add value + when typeof(value) is seq[Mesh]: + assert not value.isNil, &"Cannot add a mesh that is 'nil': " & name + scene.meshes.add value proc addShaderGlobal*[T](scene: var Scene, name: string, data: T) = scene.shaderGlobals[name] = newDataList(thetype=getDataType[T]())