From c4f64ec4e2d4d358070882705113b32d25c9647f Mon Sep 17 00:00:00 2001 From: Calixte DENIZET Date: Wed, 3 Jun 2015 16:49:19 +0200 Subject: [PATCH] Bug 13834 fixed: NPE when too many strings are drawn Change-Id: I452ee2d86d891ea464feb5fc519f0f2c82ad38a0 --- scilab/CHANGES_5.5.X | 2 + .../graphics/tests/nonreg_tests/bug_13834.dia.ref | 20 ++++++ .../graphics/tests/nonreg_tests/bug_13834.tst | 24 ++++++++ .../renderer/JoGLView/text/TextManager.java | 64 ++++++++++---------- 4 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 scilab/modules/graphics/tests/nonreg_tests/bug_13834.dia.ref create mode 100644 scilab/modules/graphics/tests/nonreg_tests/bug_13834.tst diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index 8a07333..0a0e13a 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -6,6 +6,8 @@ Scilab Bug Fixes * Bug #13829 fixed - mean and sum functions returned wrong results for hypermatrices. +* Bug #13834 fixed - Drawing a high number of strings in a figure generated a Java exceptions. + * Bug #13854 fixed - On some operating systems, SciNotes did not initialize a new document at startup. * Bug #13866 fixed - There were some issues with FFTW3 library. diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13834.dia.ref b/scilab/modules/graphics/tests/nonreg_tests/bug_13834.dia.ref new file mode 100644 index 0000000..8987386 --- /dev/null +++ b/scilab/modules/graphics/tests/nonreg_tests/bug_13834.dia.ref @@ -0,0 +1,20 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// <-- TEST WITH GRAPHIC --> +// <-- Non-regression test for bug 13834 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13834 +// +// <-- Short Description --> +// NPE when too many strings are drawn +// Just check that there is no NPE printed in the terminal +f=scf(); +f.children(1).data_bounds = [0 0; 500 500]; +x=linspace(1,400,1000); +y=linspace(1,400,1000); +xstring(x, y, string(x)); diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13834.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_13834.tst new file mode 100644 index 0000000..3d769fc --- /dev/null +++ b/scilab/modules/graphics/tests/nonreg_tests/bug_13834.tst @@ -0,0 +1,24 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= + +// <-- TEST WITH GRAPHIC --> + +// <-- Non-regression test for bug 13834 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13834 +// +// <-- Short Description --> +// NPE when too many strings are drawn + +// Just check that there is no NPE printed in the terminal + +f=scf(); +f.children(1).data_bounds = [0 0; 500 500]; +x=linspace(1,400,1000); +y=linspace(1,400,1000); +xstring(x, y, string(x)); \ No newline at end of file diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java index c0208c0..7e61e1b 100644 --- a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java +++ b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/text/TextManager.java @@ -89,47 +89,49 @@ public class TextManager { Integer parentAxesId = text.getParentAxes(); Axes parentAxes = (Axes) GraphicController.getController().getObjectFromId(parentAxesId); - double[][] factors = parentAxes.getScaleTranslateFactors(); - Double[] pos = text.getPosition(); - pos[0] = pos[0] * factors[0][0] + factors[1][0]; - pos[1] = pos[1] * factors[0][1] + factors[1][1]; - pos[2] = pos[2] * factors[0][2] + factors[1][2]; + if (parentAxes != null) { + double[][] factors = parentAxes.getScaleTranslateFactors(); + Double[] pos = text.getPosition(); + pos[0] = pos[0] * factors[0][0] + factors[1][0]; + pos[1] = pos[1] * factors[0][1] + factors[1][1]; + pos[2] = pos[2] * factors[0][2] + factors[1][2]; - Vector3d textPosition = new Vector3d(pos); + Vector3d textPosition = new Vector3d(pos); - /* Compute the text box vectors and the text box to texture dimension ratios */ - Vector3d[] textBoxVectors = computeTextBoxVectors(projection, text, texture.getDataProvider().getTextureSize(), parentAxes); - double[] ratios = computeRatios(projection, text, textBoxVectors, texture.getDataProvider().getTextureSize(), spriteDims); + /* Compute the text box vectors and the text box to texture dimension ratios */ + Vector3d[] textBoxVectors = computeTextBoxVectors(projection, text, texture.getDataProvider().getTextureSize(), parentAxes); + double[] ratios = computeRatios(projection, text, textBoxVectors, texture.getDataProvider().getTextureSize(), spriteDims); - /* If text box mode is equal to filled, the texture must be updated */ - if (text.getTextBoxMode() == 2 && ratios[0] != 1.0) { - texture = updateSprite(colorMap, text, ratios[0], ratios[1]); - } + /* If text box mode is equal to filled, the texture must be updated */ + if (text.getTextBoxMode() == 2 && ratios[0] != 1.0) { + texture = updateSprite(colorMap, text, ratios[0], ratios[1]); + } - /* Compute the text texture's actual position, which depends on the object's text box mode property */ - Vector3d[] cornerPositions = computeTextPosition(projection, text, textBoxVectors, texture.getDataProvider().getTextureSize()); + /* Compute the text texture's actual position, which depends on the object's text box mode property */ + Vector3d[] cornerPositions = computeTextPosition(projection, text, textBoxVectors, texture.getDataProvider().getTextureSize()); - /* Draw in window coordinates */ - drawingTools.getTransformationManager().useWindowCoordinate(); + /* Draw in window coordinates */ + drawingTools.getTransformationManager().useWindowCoordinate(); - /* The Text object's rotation direction convention is opposite to the standard one, its angle is expressed in radians. */ - drawingTools.draw(texture, AnchorPosition.LOWER_LEFT, cornerPositions[0], -180.0 * text.getFontAngle() / Math.PI); + /* The Text object's rotation direction convention is opposite to the standard one, its angle is expressed in radians. */ + drawingTools.draw(texture, AnchorPosition.LOWER_LEFT, cornerPositions[0], -180.0 * text.getFontAngle() / Math.PI); - drawingTools.getTransformationManager().useSceneCoordinate(); + drawingTools.getTransformationManager().useSceneCoordinate(); - /* Compute the corners of the text's bounding box in window coordinates */ - Vector3d[] projCorners; - if (text.getTextBoxMode() == 2) { - projCorners = computeProjTextBoxCorners(cornerPositions[1], text.getFontAngle(), textBoxVectors); - } else { - projCorners = computeProjCorners(cornerPositions[0], text.getFontAngle(), texture.getDataProvider().getTextureSize()); - } + /* Compute the corners of the text's bounding box in window coordinates */ + Vector3d[] projCorners; + if (text.getTextBoxMode() == 2) { + projCorners = computeProjTextBoxCorners(cornerPositions[1], text.getFontAngle(), textBoxVectors); + } else { + projCorners = computeProjCorners(cornerPositions[0], text.getFontAngle(), texture.getDataProvider().getTextureSize()); + } - Vector3d[] corners = computeCorners(projection, projCorners, parentAxes); - Double[] coordinates = cornersToCoordinateArray(corners); + Vector3d[] corners = computeCorners(projection, projCorners, parentAxes); + Double[] coordinates = cornersToCoordinateArray(corners); - /* Set the computed coordinates */ - text.setCorners(coordinates); + /* Set the computed coordinates */ + text.setCorners(coordinates); + } } /** -- 1.7.9.5