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

Crashes on large word sizes #14

Open
lafncow opened this issue Jul 9, 2013 · 12 comments
Open

Crashes on large word sizes #14

lafncow opened this issue Jul 9, 2013 · 12 comments
Assignees
Labels

Comments

@lafncow
Copy link

lafncow commented Jul 9, 2013

If the size for a word is too large, the script will crash on line 509 of the getTextInfo method, ie:

// Get the pixels of the text
var imageData = fctx.getImageData(0, 0, width, height).data;

...giving this error:

Cannot read property 'data' of null

It can be duplicated by running this on a 800px x 1200px canvas:

WordCloud( myCanvas, { list : [["my",173],["spoon",283],["is",173],["too",283],["big",6283]] });

I may be mistaken, but my expected behavior was that the entire cloud would scale down so that the extra large word(s) fit.

This happens in Chrome, I have not tested other browsers.

@ghost ghost assigned timdream Jul 10, 2013
@timdream
Copy link
Owner

Thanks for filing!

@timdream
Copy link
Owner

Oh crap, I can actually crash the tab on Chrome with your code here ...

@timdream
Copy link
Owner

... and Firefox hangs w/o any way to recover. I would have to kill the browser.

@timdream
Copy link
Owner

I now concluded this is a bug of the browser, or even the canvas API, but not on the library side. The browsers died at getImageData() call presumably the large TypedArray data flood into the memory.

I'll file bugs on Firefox and Chrome.

There is no way in JavaScript to know the size limit of the array, or canvas. The way to fix this here would be expose a config allowing people to set a size limit, but again, deciding that limit will be a problem.

@timdream
Copy link
Owner

Sorry for the delay, Firefox bug filed https://bugzilla.mozilla.org/show_bug.cgi?id=952909

@speg
Copy link

speg commented May 26, 2014

+1 what's the safe way to work around this? I get the same error even with small values, if they come after an even smaller value. e.g., [..., ['Foo', 10], ['Bar', 11]]

@timdream
Copy link
Owner

Maybe your canvas is too big so the resulting pixel size of word to draw need to be big? Maybe your weightFactor is set too big?

I don't have a way to workaround this, as I previously stated.

@JacquiManzi
Copy link
Contributor

I personally have not run into this issue with count values as small as the ones in speg's comment, but have run into it with much larger values. The way I safely got around this was to pick a max count value that would not cause the browser to crash and normalize all count values based on the max value.

As tim suggested, I would definitely make sure your weight factor is not too big as well.

@Kiel-H-Byrne
Copy link

Is this still an issue?
My wordcloud crashes servers (i deployed to a meteor server and it crashed that server).
I thought it crashed when the result set was too large, not necessarily because of word size... i have a formula set so the size of the word doesn't get too large. And i only implented that because when the words were too large they would write over the whole screen (behind other dom elements, kinda looked like a nice background feature)

but nevertheless... i'm wondering if large word sets are causing this to crash?

@timdream
Copy link
Owner

I don't know how meteor renders canvases on server (maybe w/ a headless WebKit/Chromium?), but I would imagine this issue is still valid.

@ajm113
Copy link

ajm113 commented Mar 18, 2016

An easy way to fix this issue is to 'normalize' the array of word's weights. So that the range of weight can only be 10-20, 10-50, etc.. So your not plugging in raw weights, that may cause the browser to crash or have that particular line return 'null'.

Would be nice if the library normalized the weights for you. ;)

@jctelo
Copy link

jctelo commented Apr 14, 2016

@ajm113 you're a genious! It worked for me :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants