729 views
in GUI Development by

WebGL builds break if there is an if-else ladder over 32 rungs long ... ?!

if (Label == "None")
  return 0;
else if (Label == "pAtm")
  return 1;
else if (Label == "CO2r")
  return 2;
else if (Label == "CO2a")
  return 3;
else if (Label == "CO2d")
  return 4;
else if (Label == "H2Or")
  return 5;
else if (Label == "H2Oa")
  return 6;
else if (Label == "H2Od")
  return 7;
else if (Label == "Tcuv")
  return 8;
else if (Label == "Tleaf")
  return 9;
else if (Label == "Tamb")
  return 10;
else if (Label == "PARe")
  return 11;
else if (Label == "PARi")
  return 12;
else if (Label == "Flow")
  return 13;
    
else if (Label == "RH%%")
  return 14;
else if (Label == "A")
  return 15;
else if (Label == "Ci")
  return 16;
else if (Label == "E")
  return 17;
else if (Label == "gs")
  return 18;
else if (Label == "WUE")
  return 19;  
else if (Label == "VPD")
  return 20;        
else if (Label == "F")
  return 21;
else if (Label == "Fo")
  return 22;
else if (Label == "Fm")
  return 23;
else if (Label == "Fv")
  return 24;
else if (Label == "Fv/Fm")
  return 25;
else if (Label == "Fs")
  return 26;
else if (Label == "Fm'")
  return 27;
else if (Label == "Fv'")
  return 28;  
else if (Label == "phiPSII")
  return 29;
else if (Label == "Fo^")
  return 30;
else if (Label == "Fv'/Fm'")
  return 31; 
else if (Label == "qP")
  return 32;

else if (Label == "qNP")
  return 33;  

else
  return 100;

/* The template just returns the given argument... */
//return Label;

 

 

 

1 Answer

0 votes
by

Hello Mike,

thank you very much for this error report. I am able to reproduce this behavior. The problem is caused in the row 51076. Due to missing space in the actual row the operand for the return statement has been moved to the next row. In JavaScript the last statement within a row does not need to be terminated with ';'. Accordingly, the return statement is considered as not having any operands and the value 33 is considered as not belonging to the return statement. We will have to adapt the JavaScript Code Generator to take this special case in account. I put this issue on the to-do list for our next version.

As workaround just remove all else statement from your implementation. These are not necessary since in case of an if-condition being fulfilled the method is left with the return statement. For example:

if (Label == "None") return 0;
if (Label == "pAtm") return 1;
if (Label == "CO2r") return 2;
...

Another workaround is to generate the code with activated obfuscation. The obfuscator takes care of not wrapping text rows at inadequate positions.

Does it help you?

Best regards

Paul Banach

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...