summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-11-10 06:00:50 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-11-10 06:00:50 +0100
commit7966948062e55fac965d1a6a13b848dc0df78a9f (patch)
tree5d6f9093783c0947f3a263dd035ef1c145158c36
parentb12ca99506c7538a74cb2ed39ce0e1781e934a2a (diff)
downloadreduced_system_layer-7966948062e55fac965d1a6a13b848dc0df78a9f.zip
Remove asserts
-rw-r--r--Dockerfile4
-rwxr-xr-xexamples/graph.c33
2 files changed, 23 insertions, 14 deletions
diff --git a/Dockerfile b/Dockerfile
index 9875b94..a4750ca 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,9 @@
FROM alpine as build
RUN apk add clang lld
-COPY examples/ui.c /usr/examples/ui.c
+COPY examples /usr/examples
COPY reduced_system_layer.c /usr/reduced_system_layer.c
COPY graphics.c /usr/graphics.c
-RUN clang --target=wasm32 -nostdlib -Wl,--no-entry,--allow-undefined -o /usr/index.wasm /usr/examples/ui.c
+RUN clang --target=wasm32 -nostdlib -Wl,--no-entry,--allow-undefined -o /usr/index.wasm /usr/examples/graph.c
FROM nginx:alpine
EXPOSE 80
diff --git a/examples/graph.c b/examples/graph.c
index edbb5b3..685f8b7 100755
--- a/examples/graph.c
+++ b/examples/graph.c
@@ -75,7 +75,8 @@ b8 check_edge_index(i64 edge_index) {
}
void draw_node(i64 node_index) {
- assert(check_node_index(node_index));
+ if (!check_node_index(node_index))
+ return;
Node n = world.nodes[node_index];
@@ -97,7 +98,8 @@ void draw_node(i64 node_index) {
}
void draw_edge(i64 edge_index) {
- assert(check_edge_index(edge_index));
+ if (!check_edge_index(edge_index))
+ return;
Edge e = world.edges[edge_index];
Node n0 = world.nodes[e.src];
@@ -134,7 +136,8 @@ void draw_graph(void) {
}
void update_node(i64 node_index) {
- assert(check_node_index(node_index));
+ if (!check_node_index(node_index))
+ return;
Node n = world.nodes[node_index];
@@ -149,7 +152,8 @@ void update_node(i64 node_index) {
}
void update_edge(i64 edge_index) {
- assert(check_edge_index(edge_index));
+ if (!check_edge_index(edge_index))
+ return;
Edge e = world.edges[edge_index];
Node n0 = world.nodes[e.src];
@@ -167,13 +171,15 @@ void update_edge(i64 edge_index) {
}
void remove_edge(i64 edge_index) {
- assert(check_edge_index(edge_index));
+ if (!check_edge_index(edge_index))
+ return;
world.edges[edge_index].enabled = 0;
}
void remove_node(i64 node_index) {
- assert(check_node_index(node_index));
+ if (!check_node_index(node_index))
+ return;
for (i64 i = 0; i < MAX_NUM_EDGES; ++i)
if (world.edges[i].enabled && (world.edges[i].src == node_index || world.edges[i].dst == node_index))
@@ -203,7 +209,8 @@ void add_node(f64 x, f64 y) {
while (node_index < MAX_NUM_NODES && world.nodes[node_index].enabled)
++node_index;
- assert(node_index < MAX_NUM_NODES);
+ if (node_index >= MAX_NUM_NODES)
+ return;
world.nodes[node_index] = (Node) {
.enabled = 1,
@@ -214,8 +221,9 @@ void add_node(f64 x, f64 y) {
}
void add_edge(i64 src, i64 dst) {
- assert(check_node_index(src));
- assert(check_node_index(dst));
+ if (!check_node_index(src) ||
+ !check_node_index(dst))
+ return;
if (src == dst)
return;
@@ -232,7 +240,8 @@ void add_edge(i64 src, i64 dst) {
while (edge_index < MAX_NUM_EDGES && world.edges[edge_index].enabled)
++edge_index;
- assert(edge_index < MAX_NUM_EDGES);
+ if (edge_index >= MAX_NUM_EDGES)
+ return;
world.edges[edge_index] = (Edge) {
.enabled = 1,
@@ -314,7 +323,7 @@ void highlight_path(i64 src, i64 dst) {
//
if (world.nodes[dst].distance < 0) {
- printf("Path not found\n");
+ // printf("Path not found\n");
return;
}
@@ -360,7 +369,7 @@ void highlight_path(i64 src, i64 dst) {
//
if (min_node_index < 0) {
- printf("Internal error\n");
+ // printf("Internal error\n");
break;
}