Skip to content

Commit c0e7189

Browse files
authored
Merge pull request #160 from 00alia00/debug-for-change-crash
Warn when removing bad refcount
2 parents cfb7ddd + 3be1c45 commit c0e7189

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/changes/ReferenceTracker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ export class ReferenceTracker {
2727
}
2828

2929
// for decoding
30-
removeRef(refId) {
31-
this.refCounts[refId] = this.refCounts[refId] - 1;
30+
removeRef(refId: number) {
31+
const refCount = this.refCounts[refId];
32+
if (refCount === undefined) {
33+
console.warn(`trying to remove reference ${refId} that doesn't exist`);
34+
return;
35+
}
36+
if (refCount === 0) {
37+
console.warn(`trying to remove reference ${refId} with 0 refCount`);
38+
return;
39+
}
40+
41+
this.refCounts[refId] = refCount - 1;
3242
this.deletedRefs.add(refId);
3343
}
3444

0 commit comments

Comments
 (0)