I start debugging this piece of code
public void redrawGraphic(Function func, int color){ canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle clientArea = canvas.getClientArea(); e.gc.setLineWidth(1); e.gc.setForeground(e.display.getSystemColor(color)); for (int currFunc = 0; currFunc < func.size() - 1; currFunc++) { if ((int)Math.round(abs(func.getPoint(currFunc).y)) <= clientArea.height/LINES_SPACE*currScale/2 + currPixelsCenterX + 1) { int key0 = (int)Math.round(func.getPoint(currFunc).x / currScale * LINES_SPACE) + clientArea.width / 2; int value0 = -(int)Math.round(func.getPoint(currFunc).y / currScale * LINES_SPACE) + clientArea.height / 2; int key1 = (int)Math.round(func.getPoint(currFunc + 1).x / currScale * LINES_SPACE) + clientArea.width / 2; int value1 = -(int)Math.round(func.getPoint(currFunc + 1).y / currScale * LINES_SPACE) + clientArea.height / 2; e.gc.drawLine(key0 - currPixelsCenterX, value0 + currPixelsCenterY, key1 - currPixelsCenterX, value1 + currPixelsCenterY); } } } }); }
When step over jumps over the block
new PaintListener() {}
When step into the variables of the canvas writes "No such instance field: 'canvas'", although this field is initialized. If you remove the entire contents of the block - the result is the same.
I have a suspicion that synchronization is to blame.
public void drawNewPoint(){ Display.getDefault().asyncExec(new Runnable () { public void run() { lock.lock(); try { while (model.isReadyToDraw) { condition.await(); } Thread.sleep(model.getMsSleepTime()); model.isReadyToDraw = true; System.out.println(model.sharedPoint.x + " " + model.sharedPoint.y); model.addSharedLinearPoint(); //вот тут вызываю метод, листинг которого выше graphicsController.redrawGraphic(model.getLinearFunction(), SWT.COLOR_GREEN); condition.signalAll(); } catch (InterruptedException e) { System.out.println(e.getMessage()); } finally { lock.unlock(); } } }); }
The method above is performed in a class that implements Runnable, where it is synchronized with another thread that performs the calculations.
What is the reason?