Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Verify valid state after updating spatial index
Browse files Browse the repository at this point in the history
We're seeing some rare exceptions in production that seemed to be caused
by the spatial index getting into an invalid state, where it implies the
existence of rows beyond the end of the last buffer row. This carries a
cost but we want to find out if and when this is happening in
production.
  • Loading branch information
Nathan Sobo committed Feb 14, 2017
1 parent c6985ef commit dac8c8b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/display-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ class DisplayLayer {
screenPosition = this.collapseHardTabs(screenPosition, tabCount, clipDirection)
}
const bufferPosition = this.translateScreenPositionWithSpatialIndex(screenPosition, clipDirection, skipSoftWrapIndentation)

if (global.atom && bufferPosition.row >= this.buffer.getLineCount()) {
global.atom.assert(false, 'Invalid translated buffer row', {
bufferPosition, bufferLineCount: this.buffer.getLineCount()
})
return this.buffer.getEndPosition()
}

const columnDelta = this.getClipColumnDelta(bufferPosition, clipDirection)
if (columnDelta !== 0) {
return Point(bufferPosition.row, bufferPosition.column + columnDelta)
Expand Down Expand Up @@ -956,6 +964,18 @@ class DisplayLayer {
new Array(insertedScreenLineLengths.length)
)

if (global.atom && this.indexedBufferRowCount === this.buffer.getLineCount()) {
const lastScreenRow = this.getLastScreenRow()
const lastScreenColumn = this.lineLengthForScreenRow(lastScreenRow)
const translatedEndPosition = this.translateScreenPosition(Point(lastScreenRow, lastScreenColumn))
const expectedEndPosition = this.buffer.getEndPosition()
if (!translatedEndPosition.isEqual(expectedEndPosition)) {
global.atom.assert(false, 'Invalid spatial index state', {
lastScreenRow, lastScreenColumn, translatedEndPosition, expectedEndPosition,
})
}
}

return {
start: Point(startScreenRow, 0),
oldExtent: Point(oldScreenRowCount, 0),
Expand Down

0 comments on commit dac8c8b

Please sign in to comment.