Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experienced a lot of crashes #51

Closed
supriyakhankarnw18 opened this issue Jul 13, 2021 · 20 comments · Fixed by #58
Closed

Experienced a lot of crashes #51

supriyakhankarnw18 opened this issue Jul 13, 2021 · 20 comments · Fixed by #58

Comments

@supriyakhankarnw18
Copy link

Light weight chart

We have experienced a lot of crashes in the chart. I have attached a screenshot of the log.
Could you rectify/assist us with this

@timocov
Copy link
Contributor

timocov commented Jul 21, 2021

@makedonsky94 can you please take a look?

@supriyakhankarnw18
Copy link
Author

@makedonsky94 - Any ETA for this. Its very bad user experience

@supriyakhankarnw18
Copy link
Author

@makedonsky94 Please have a look at the line number in the below screenshot where the crash is happening.

Capture

@makedonsky94
Copy link
Contributor

Hi! We are working on this. At the moment we could not say what causing the crash. It would be helpful if you provide more details on your case

@supriyakhankarnw18
Copy link
Author

Hi we are facing this crash onSeriesCreated on the below code

api.setData(data.list.map { it as LineData })

@makedonsky94
Copy link
Contributor

Do you have logs for that crash? I mean can you determine what happening in the code before the crash? Do you recreate the series and then set the data? Or is it happening right after the initialization of chart?

@supriyakhankarnw18
Copy link
Author

supriyakhankarnw18 commented Jul 30, 2021

@makedonsky94 Please have a look at the cash log as below

java.lang.IllegalStateException: Value is null
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController.onMessage(WebMessageController.kt:124)
    at com.tradingview.lightweightcharts.runtime.WebMessageChannel$1.onMessage(WebMessageChannel.kt:26)
    at androidx.webkit.internal.WebMessagePortImpl$1.onMessage(WebMessagePortImpl.java:111)
    at nk.a(chromium-Monochrome.aab-stable-410410173:3)
    at hR2.handleMessage(chromium-Monochrome.aab-stable-410410173:6)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.IllegalStateException
    at dalvik.system.VMStack.getThreadStackTrace(Native Method)
    at java.lang.Thread.getStackTrace(Thread.java:1538)
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController.callBridgeFunction(WebMessageController.kt:56)
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController.callBridgeFunction$default(WebMessageController.kt:48)
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController.callFunction(WebMessageController.kt:22)
    at com.tradingview.lightweightcharts.api.delegates.SeriesApiDelegate.setData(SeriesApiDelegate.kt:37)
    at com.moneycontrol.handheld.fragments.StockDetailRevampFragment$createSeriesWithData$2.invoke(StockDetailRevampFragment.kt:2462)
    at com.moneycontrol.handheld.fragments.StockDetailRevampFragment$createSeriesWithData$2.invoke(StockDetailRevampFragment.kt:111)
    at com.tradingview.lightweightcharts.api.delegates.ChartApiDelegate$addAreaSeries$1.invoke(ChartApiDelegate.kt:71)
    at com.tradingview.lightweightcharts.api.delegates.ChartApiDelegate$addAreaSeries$1.invoke(ChartApiDelegate.kt:26)
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController$BufferElement.invoke(WebMessageController.kt:155)
    at com.tradingview.lightweightcharts.runtime.controller.WebMessageController.onMessage(WebMessageController.kt:104)
    at com.tradingview.lightweightcharts.runtime.WebMessageChannel$1.onMessage(WebMessageChannel.kt:26) 
    at androidx.webkit.internal.WebMessagePortImpl$1.onMessage(WebMessagePortImpl.java:111)

@makedonsky94
Copy link
Contributor

I suppose that you can send an empty date value in bar data which leads to crash.
What we can do at the moment:

  • add verification of datetime input
  • add stacktrace from javascript backend for better understanding of crashes.

We are working on the new version of library so you will see that changes in the nearest update.

@supriyakhankarnw18
Copy link
Author

supriyakhankarnw18 commented Aug 3, 2021

When should we expect the update?

@makedonsky94
Copy link
Contributor

We expect releasing of the library this month. If you want to fix this crash right now, please consider to make your own checks for correctness of bar data

@makedonsky94 makedonsky94 linked a pull request Aug 4, 2021 that will close this issue
@makedonsky94
Copy link
Contributor

At 3.5 we've improved crash logs. I guess that will make much easier to find an issue in your code. Pleases make an update of library version in the project and send us a new crashlog

@supriyakhankarnw18
Copy link
Author

okay sure.

@supriyakhankarnw18
Copy link
Author

@makedonsky94 Please have a look at the cash log below

Caused by: java.lang.IllegalStateException: Error: Value is null
at jsCode.ensureNotNull(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:299)
at jsCode.TimeScale._private__doFixLeftEdge(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:3509)
at jsCode.TimeScale._internal_setBaseIndex(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:3165)
at jsCode.ChartModel._internal_updateTimeScale(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:7102)
at jsCode.ChartApi._private__sendUpdateToChart(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:10936)
at jsCode.ChartApi._internal_applyNewData(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:10898)
at jsCode.SeriesApi.setData(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:10329)
at jsCode.SeriesFunctionManager.findSeries(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:11349)
at jsCode.Object.functionRef(file:///android_asset/com/tradingview/lightweightcharts/scripts/app/main.js:11251)

@timocov
Copy link
Contributor

timocov commented Aug 18, 2021

@supriyakhankarnw18 is there any way how we can reproduce it locally either with your app? The error is really strange and I'm just wonder how it might happen.

@supriyakhankarnw18
Copy link
Author

supriyakhankarnw18 commented Aug 18, 2021

@timocov there is one scenario our QA found while performing stress testing where we are getting the same crash, so here the crash occurs.
We are attaching the video reference for the same, please look into it.

LightWeighChartCrash2.mp4
lightweightchartcharh1.mp4

We are sure that this kind of scenario may not be performed at the user level, but we are able to get a similar crash from the users in Crashylatics logs that are unable to track/reproduce at our end.

@timocov
Copy link
Contributor

timocov commented Aug 18, 2021

@supriyakhankarnw18 if you can reproduce it locally somehow, is it possible to log all actions you do with lightweight-charts so we can try to reproduce them locally by using your steps? I mean, you can log every API call with all arguments so we can replicate all steps ourselves

@supriyakhankarnw18
Copy link
Author

@timocov after every API call we are calling this below method to set the data and load the chart

private fun createSeriesWithData(
data: Data,
priceScale: PriceScaleId,
chartApi: ChartApi,
onSeriesCreated: (SeriesApi) -> Unit) {

    try {
        when (data.type) {
            SeriesDataType.AREA -> {
                if (data.direction == 1) {
                    chartApi.addAreaSeries(
                            options = AreaSeriesOptions(
                                    lineColor = Color.argb(255, 76, 175, 80).toIntColor(),
                                    topColor = Color.argb(143, 76, 175, 80).toIntColor(),
                                    bottomColor = Color.argb(10, 76, 175, 80).toIntColor(),
                                    lineWidth = LineWidth.TWO
                            ),
                            onSeriesCreated = { api ->
                                api.setData(data.list.map { it as LineData })
                                chartApi.timeScale.fitContent()
                                val options = PriceLineOptions(
                                        lineWidth = LineWidth.TWO,
                                        lineStyle = LineStyle.SOLID,
                                        axisLabelVisible = true
                                )
                                onSeriesCreated(api)
                            }
                    )
                } else {
                    chartApi.addAreaSeries(
                            options = AreaSeriesOptions(
                                    priceScaleId = priceScale,
                                    lineColor = Color.rgb(227, 81, 90).toIntColor(),
                                    topColor = Color.argb(143, 227, 81, 90).toIntColor(),
                                    bottomColor = Color.argb(10, 227, 81, 90).toIntColor(),
                                    lineWidth = LineWidth.TWO
                            ),
                            onSeriesCreated = { api ->
                                api.setData(data.list.map { it as LineData })
                                chartApi.timeScale.fitContent()
                                val options = PriceLineOptions(
                                        lineWidth = LineWidth.ONE,
                                        lineStyle = LineStyle.SOLID,
                                        axisLabelVisible = true
                                )
                                onSeriesCreated(api)
                            }
                    )
                }
            }

            SeriesDataType.CANDLESTICK -> {
                if (Utility.isDarkTheme(requireContext())) {
                    chartApi.addCandlestickSeries(
                            options = CandlestickSeriesOptions(
                                    upColor = Color.parseColor("#95CD4F").toIntColor(),
                                    borderUpColor = Color.parseColor("#95CD4F").toIntColor(),
                                    wickUpColor = Color.parseColor("#95CD4F").toIntColor(),
                                    downColor = Color.parseColor("#D6524F").toIntColor(),
                                    borderDownColor = Color.parseColor("#D6524F").toIntColor(),
                                    wickDownColor = Color.parseColor("#D6524F").toIntColor()
                            ),
                            onSeriesCreated = { api ->
                                api.setData(data.list)
                                chartApi.timeScale.fitContent()
                                onSeriesCreated(api)
                            }
                    )
                } else {
                    chartApi.addCandlestickSeries(
                            options = CandlestickSeriesOptions(
                                    upColor = Color.parseColor("#26a69a").toIntColor(),
                                    borderUpColor = Color.parseColor("#26a69a").toIntColor(),
                                    wickUpColor = Color.parseColor("#26a69a").toIntColor(),
                                    downColor = Color.parseColor("#ef5350").toIntColor(),
                                    borderDownColor = Color.parseColor("#ef5350").toIntColor(),
                                    wickDownColor = Color.parseColor("#ef5350").toIntColor()
                            ),
                            onSeriesCreated = { api ->
                                api.setData(data.list)
                                chartApi.timeScale.fitContent()
                                onSeriesCreated(api)
                            }
                    )
                }
            }
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

have shared the line on which we are getting crash

#51 (comment)

It seems like a Threading issue inside the library

@timocov
Copy link
Contributor

timocov commented Aug 18, 2021

I'm just curious what can you do (even in multi-threaded/async environment) with lightweight-charts so it will fail like this. The error you shown in #51 (comment) is really strange and looking in the code of lightweight-charts I cannot even image the case why it might happen (let's say you have an array, and you just checked whether it is empty or not, and after that you take the first element but it doesn't exist).

@supriyakhankarnw18
Copy link
Author

@timocov These are some more logs from Crashlytics

WhatsApp Image 2021-08-19 at 1 59 11 PM (1)
WhatsApp Image 2021-08-19 at 1 59 11 PM

@timocov
Copy link
Contributor

timocov commented Aug 20, 2021

Ok, it seems that I figured out why this happened. For some reason the size of the container for lightweight-charts is 0x0 what leads for this error. We'll fix it from our side, but as workaround you can always provide positive size of the chart by providing the size explicitly via options.

Please track tradingview/lightweight-charts#821 for the fix. I'm going to close this issue.

@timocov timocov closed this as completed Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants