Skip to content

Commit 9202acf

Browse files
HeikoKlarefedejeanne
authored andcommitted
Fix AIOBE when calculating curve in TextMergeViewer
The TextMergeViewer currently assumes that the center canvas between the two source code views always has a width of 34 points (exposed as getCenterWidth()). This width is also assumed when calculating the curve connecting regions between the two source viewers. Even though that size for the center canvas is set by the used layout, there is no guarantee that the size is an invariant that does always hold. In particular, during a zoom change on Windows, the shell and its controls are temporarily resized by the OS until the layout is applied again, so that temporarily the size does not equal 34 points and a paint operation can fail with an AIOBE. This change adapts the curve calculation to adhere to the actual current width of the canvas instead of assuming the size to be invariant. Fixes #2584
1 parent 4d9d68a commit 9202acf

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,26 +4593,25 @@ private void paintCenter(Canvas canvas, GC g) {
45934593
}
45944594

45954595
private int[] getCenterCurvePoints(int startx, int starty, int endx, int endy) {
4596-
if (fBasicCenterCurve == null) {
4597-
buildBaseCenterCurve(endx-startx);
4596+
int width = endx - startx;
4597+
if (fBasicCenterCurve == null || fBasicCenterCurve.length != width) {
4598+
fBasicCenterCurve = buildBaseCenterCurve(width);
45984599
}
45994600
double height= endy - starty;
46004601
height= height/2;
4601-
int width= endx-startx;
46024602
int[] points= new int[width];
46034603
for (int i= 0; i < width; i++) {
46044604
points[i]= (int) (-height * fBasicCenterCurve[i] + height + starty);
46054605
}
46064606
return points;
46074607
}
46084608

4609-
private void buildBaseCenterCurve(int w) {
4610-
double width= w;
4611-
fBasicCenterCurve= new double[getCenterWidth()];
4612-
for (int i= 0; i < getCenterWidth(); i++) {
4613-
double r= i / width;
4614-
fBasicCenterCurve[i]= Math.cos(Math.PI * r);
4609+
private double[] buildBaseCenterCurve(int width) {
4610+
double[] curve = new double[width];
4611+
for (int x = 0; x < width; x++) {
4612+
curve[x] = Math.cos(Math.PI * x / width);
46154613
}
4614+
return curve;
46164615
}
46174616

46184617
private int calculateShift(MergeSourceViewer tp) {

0 commit comments

Comments
 (0)