Pre loader

I crashed when I was quick to show and hide the content of the chart

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

I crashed when I was quick to show and hide the content of the chart。

The source code is similar to the following:

public void show(){
if(!surface.getRenderableSeries().contains(lineUpSeries)) {
Collections.addAll(surface.getRenderableSeries(), lineUpSeries);
Collections.addAll(surface.getRenderableSeries(), lineDownSeries);
Collections.addAll(surface.getRenderableSeries(), line20Series);
Collections.addAll(surface.getAnnotations(), upTextMarker);
Collections.addAll(surface.getAnnotations(), downTextMarker);
Collections.addAll(surface.getAnnotations(), ma20TextMarker);
Collections.addAll(surface.getAnnotations(), upAxisMarker);
Collections.addAll(surface.getAnnotations(), downAxisMarker);
Collections.addAll(surface.getAnnotations(), ma20AxisMarker);
}
}
public void hide(){
if(surface.getRenderableSeries().contains(lineUpSeries)) {
surface.getRenderableSeries().remove(lineUpSeries);
surface.getRenderableSeries().remove(lineDownSeries);
surface.getRenderableSeries().remove(line20Series);
surface.getAnnotations().remove(upTextMarker);
surface.getAnnotations().remove(downTextMarker);
surface.getAnnotations().remove(ma20TextMarker);
surface.getAnnotations().remove(upAxisMarker);
surface.getAnnotations().remove(downAxisMarker);
surface.getAnnotations().remove(ma20AxisMarker);
}
}

error log:

java.lang.NullPointerException: Attempt to invoke interface method ‘boolean com.scichart.charting.visuals.annotations.IAnnotationPlacementStrategy.isInBounds(com.scichart.charting.visuals.annotations.AnnotationCoordinates, com.scichart.charting.visuals.annotations.IAnnotationSurface)’ on a null object reference
at com.scichart.charting.visuals.annotations.AnnotationBase.a(SourceFile:1207)
at com.scichart.charting.visuals.annotations.AnnotationBase.update(SourceFile:1105)
at com.scichart.charting.visuals.annotations.AxisMarkerAnnotation.update(SourceFile:246)
at com.scichart.charting.visuals.annotations.AnnotationBase.update(SourceFile:1083)
at com.scichart.charting.visuals.rendering.RenderSurfaceRenderer.a(SourceFile:327)
at com.scichart.charting.visuals.rendering.RenderSurfaceRenderer.a(SourceFile:218)
at com.scichart.charting.visuals.rendering.RenderSurfaceRenderer.a(SourceFile:132)
at com.scichart.charting.visuals.rendering.RenderSurfaceRenderer.onDraw(SourceFile:123)
at com.scichart.drawing.opengl.RenderSurfaceGL$a.onDraw(SourceFile:228)
at com.scichart.drawing.opengl.MyGLRenderer.b(SourceFile:293)
at com.scichart.drawing.opengl.MyGLRenderer.onDrawFrame(SourceFile:277)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1548)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1259)

Version
'2.0.0.1884'
  • You must to post comments
0
0

Hi Huang,

Thanks for your question. It is known issue which is caused by fact that ObservableCollection which is used as base class for annotation collection is not thread safe. There is a race condition when annotation collection changes at the same time when chart redraws itself on another thread. Usually to prevent this exception you just need to suspend updates of chart which is modified so chart won’t be redrawn while you add/remove annotations:

    public void hide(){
    // suspend surface during update of of renderable series and annotation collections
    UpdateSuspender.using(surface, new Runnable() {
        @Override
        public void run() {
            if(surface.getRenderableSeries().contains(lineUpSeries)) {
                surface.getRenderableSeries().remove(lineUpSeries);
                surface.getRenderableSeries().remove(lineDownSeries);
                surface.getRenderableSeries().remove(line20Series);
                surface.getAnnotations().remove(upTextMarker);
                surface.getAnnotations().remove(downTextMarker);
                surface.getAnnotations().remove(ma20TextMarker);
                surface.getAnnotations().remove(upAxisMarker);
                surface.getAnnotations().remove(downAxisMarker);
                surface.getAnnotations().remove(ma20AxisMarker);
            }
        }
    });
}

Can you try and let me know if this workaround fixes the exception?

Best regards,
Yura

  • Huang haiyan
    I have another breakdown, as follows: java.lang.UnsupportedOperationException: Data has been changed to a DataSeries which is unsorted in the X-Direction. Unsorted data can have severe performance implications in SciChart. For maximum performance, please double-check that you are only inserting sorted data to SciChart. Alternatively, to disable this warning and allow unsorted data, please call dataSeries.setAcceptsUnsortedData(true). at com.scichart.charting.model.datadistributioncalculator.a.a(SourceFile:31) at com.scichart.charting.model.datadistributioncalculator.DefaultDataDistributionCalculator.a(SourceFile:148) at com.scichart.charting.model.datadistributioncalculator.DefaultDataDistributionCalculator.onInsertValues(SourceFile:86) at com.scichart.charting.model.dataSeries.XyDataSeries.insertRange(SourceFile:408)
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies