Khan / live-editor

A browser-based live coding environment.
Other
761 stars 184 forks source link

colorMode(HSB) causes error after Restart button clicked in some projects #587

Open SpongeJr opened 8 years ago

SpongeJr commented 8 years ago

Reported on ZenDesk... User is getting Cannot read property 0 of undefined! only after a restart in this program: https://www.khanacademy.org/computer-programming/new-program/6028718145 reproduced, confirmed... they're saying it's happening as a result of colorMode(HSB); on line 68, commenting it out fixes it... I can confirm this as well and have reproduced in both Chrome and Firefox.

Browser console reveals that the error is occurring here (in the minified code, see commented line). This definitely seems to go along with the thought that colorMode(HSB) has something to do with it.

https://cdn.kastatic.org/genfiles/javascript/en/scratchpads-exec-pjs-package-e05176.js line 1190

function Wr(e,t,r,i){var a,s,o,l
if(dt===p.HSB){var u=v.color.toRGB(e,t,r)
a=u[0] // Uncaught TypeError: Cannot read property '0' of undefined
s=u[1]

I don't have any simpler code for reproduction yet than the learner's project, will update if that changes.

MatthiasPortzel commented 8 years ago

On Safari I'm seeing slightly different but still weird behavior. I get the error undefined is not an object (evaluating 'v.color.toRGB(e,t,r)') immediately after navigating to the program. Commenting out then uncommenting colorMode(HSB) fixes the problem until reloading.

MatthiasPortzel commented 8 years ago

Just did some testing to find the root of the issue, namely that fill(), stroke(), and color() cannot have a negative first parameter when colorMode is HSB. This isn't a live editor issue, but a bug with processing.js as I was able to reproduce it on several other websites which use processing.js. This same bug was previously documented in #261.