diff options
| -rw-r--r-- | ttt.jai | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |
