fjenett / javascript-mode-processing

Former ProcessingJS mode (Processing 1.5) that became JavaScript mode (Processing 2.0 beta) that has now been moved out of the Processing IDE.
57 stars 13 forks source link

size(int, int) not working in javascript export when passed stored int variables Edit #11

Closed jimfingal closed 10 years ago

jimfingal commented 11 years ago

In processing 2.1 on OSX 10.7.5, I am experiencing and issue in Javascript mode when exporting a sketch for web.

In the javascript mode, when entering numbers directly into "size()", like:

size(960, 640);

The javascript correctly exports to a canvas tag correctly as:

<canvas id="sizeissue" data-processing-sources="sizeissue.pde" 
                        width="960" height="640">

However, when stored local or global int variables are passed into the function, like:

  int width = 960;
  int height = 640;
  size(int(width), int(height));

The canvas tag renders incorrectly, as:

<canvas id="sizeissue" data-processing-sources="sizeissue.pde" 
                        width="100" height="100">

When passed the variables directly, the server will not run:

  int width = 960;
  int height = 640;
  size(width, height);

And gives the error:

Exception in thread "Processing.BasicServer" java.lang.NoSuchMethodError: processing.app.Base.showWarning(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Exception;)V
    at de.bezier.mode.javascript.JavaScriptBuild.build(Unknown Source)
    at de.bezier.mode.javascript.JavaScriptBuild.export(Unknown Source)
    at de.bezier.mode.javascript.JavaScriptMode.handleExport(Unknown Source)
    at de.bezier.mode.javascript.JavaScriptEditor.handleExport(Unknown Source)
    at de.bezier.mode.javascript.JavaScriptEditor.serverStarted(Unknown Source)
    at de.bezier.mode.javascript.BasicServer.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:744)

A sketch that can replicate the issue:

void setup() 
{
  int width = 960;
  int height = 640;
 // size(960, 640);
 // size(width, height);

  size(int(width), int(height));

  background(63, 63, 63);

}

void draw() {

}
jimfingal commented 11 years ago

I see in JavaScriptBuild.java there is a warning against doing this -- but the warning doesn't get reported to the base client or exported to the html.

Thanks!

fjenett commented 10 years ago

It's not allowed/wanted in Java either .. as there is no way to correctly parse these variables during build.

http://processing.org/reference/size_.html

Do not use variables as the parameters to size() function, because it will cause problems when exporting your sketch. [...]

Yes, it could be more explicit about that.

jimfingal commented 10 years ago

Ah, yeah that makes sense / is very explicit in the documentation. That was just throwing me because I didn't see that and it worked in one place and not the other. Apologies for the spurious bug.

fjenett commented 10 years ago

All good, thanks for reporting this will someone in the future running into it ...