From 22a340479c17a6d3460b813179aee035a14e4ae2 Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Wed, 1 Sep 2021 11:17:44 -0400
Subject: fixed bug where file saving would crash if a portal was unpaired
---
source/portals.d | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
(limited to 'source/portals.d')
diff --git a/source/portals.d b/source/portals.d
index 7bb5dc2..000e182 100644
--- a/source/portals.d
+++ b/source/portals.d
@@ -23,10 +23,13 @@ struct Portal {
string toString(int[Portal* ] idMap)
in {
- assert(pair in idMap);
+ assert(pair == null || pair in idMap);
}
do {
- return format!`%s, %s: %d`(y, x, idMap[pair]);
+ if (pair == null)
+ return format!`%s, %s: -1`(y, x);
+ else
+ return format!`%s, %s: %d`(y, x, idMap[pair]);
}
void fromString(string s, Portal[int] portalsById) {
@@ -42,9 +45,7 @@ struct Portal {
s.formattedRead!"%d"(id);
auto p = id in portalsById;
if (p) {
- p.pairWith(this); // this is a REALLY big bug. Portal() is
- // being copied by value into the dict,
- // so it's not using its final ref.
+ p.pairWith(this);
}
}
--
cgit