luruxi commented on issue #9383: echarts渲染不出来报错 URL: https://github.com/apache/incubator-echarts/issues/9383#issuecomment-494314107 > I have solved this problem in my project. > > When I debuged my project, it would sometimes log the errors like this: >  > > From the errors tips, it significantly show that this error appeared when execute this code: > > ``` > this.ctx.dpr = this.dpr > ``` > > in `Layer.js` 、`Painter.js`、`zrender.js` etc. > > So I detect the Layer.js file, in `node_modules\zrender\lib\Layer.js` , I saw this code in a function named 'initContext': > > ``` > initContext: function () { > this.ctx = this.dom.getContext('2d'); > this.ctx.dpr = this.dpr; > }, > ``` > > I modified this function to the code below: > > ``` > initContext: function () { > this.ctx = this.dom.getContext('2d'); > try { > this.ctx.dpr = this.dpr; > } catch (e) { > setTimeout(() => { > location.reload() > }, 500) > } > }, > ``` > > And the bug resolved. > > I think this is a iOS bug happened occasionally, when the Layer.js or other Javascript library execute the command like `this.ctx = this.dom.getContext('2d');`,the lib find `this.dom` is not found, `this.dom` here represent the HTMLCanvasElement. It exactly is a canvas element in most time, when the iOS javascript engines display correctly, but sometimes it would not, it was not found instead. So `this.ctx` is `null`, so it will throw error when execute `this.ctx.dpr = this.dpr;`. Thank you. I'll try
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
