aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-07-29 23:17:53 +0100
committerdam <dam@gudinoff>2023-07-29 23:17:53 +0100
commit4fc88c787015268ecb658a72c17749b33200f9b9 (patch)
treeffc283e7360de1bccb4788850cd52a41394f3bb8 /ttt.jai
parent1473ed9db288f36c736726da62dd96133023a568 (diff)
downloadtask-time-tracker-4fc88c787015268ecb658a72c17749b33200f9b9.tar.zst
task-time-tracker-4fc88c787015268ecb658a72c17749b33200f9b9.zip
Fixed another bug on add_task.
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai7
1 files changed, 4 insertions, 3 deletions
diff --git a/ttt.jai b/ttt.jai
index 52d22d2..a35ac48 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -316,12 +316,13 @@ is_valid_index :: inline(db: Database, index: s64) -> bool { return index >= 0 &
add_task :: (db: *Database, task: *Task = null) -> task: *Task, index: s64 {
assert(db != null, ASSERT_NOT_NULL, "db");
- new_task: Task = .{};
- if task != null new_task = <<task;
+ // If the task belongs to this database, calling array_add might invalidate the pointer
+ // because the memory may be reallocated, thus we always use a copy of the task.
+ new_task := ifx task == null then .{} else <<task;
array_add(*db.tasks, new_task);
for * db.total_times {
- <<it = add(<<it, task.times[it_index]);
+ <<it = add(<<it, new_task.times[it_index]);
}
idx := db.tasks.count-1;