siyza / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Uncaught Input "<INPUT_NAME>" not found. #97

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I created a function with the following code, please note:
- I reduced the code and erased all parts dealing with connections, etc.
The goal of the complete function is to connect a mutator output block (such as 
"lists_create_with" and "text_join") to a value Input part of another block and 
to change the shape of the output block before it is shown on the workspace 
(and without user interaction) 

outputBlockName = 'text_join'
mutationList = [['itemCount_', 4]] (name of variable and its value)
this.block_.workspace (use the actual workspace which is similar to that of the 
block that calls this function. 

Blockly.myTest.prototype.testFunction = function(outputBlockName, mutationList) 
{
  var outputBlock = new Blockly.Block(this.block_.workspace, outputBlockName);
  outputBlock.initSvg();
  for (var i = 0; i < mutationList.length; i++) {
    outputBlock[mutationList[i][0]] = mutationList[i][1];
  }
  var container = outputBlock.mutationToDom();
  if (container) {
    outputBlock.domToMutation(container);
  };
  outputBlock.render();
  outputBlock.editable = true;  
  outputBlock.deletable = true;

  return outputBlock;
}
2. I execute the function

What is the expected output? What do you see instead?
The expected outcome is that the block directly mutates according to the value 
in the variable. I tested it with a statement block (controls_if) where the 
initial value is zero and everything worked perfectly fine. The blocks shape 
changes. 

Unfortunately in the cases of "text_join" and "lists_create_with", a delete 
operating within domtoMutation is performed to remove all inputs for the 
specified variable (itemCount_). An uncaught exception occurs and says that the 
inputs to be deleted can't be found.  

What browser are you using?
Chromium-browser 18 and Firefox 15 (taken from Ubuntu Software Center)
Ubuntu version: 11.10

Please provide any additional information below.
By adding an additional if clause to domToMutation prevents the problem, e.g. 
use in the case of "text_join" within domToMutation instead of the following 
code: 

for (var x = 0; x < this.itemCount_; x++) {
  this.removeInput('ADD' + x);
}

this code:
for (var x = 0; x < this.itemCount_; x++) {
  if (this.getInput('ADD' + x) {
    this.removeInput('ADD' + x);
  }
}

Unfortunately if the variable value is set to a number below the initial one it 
is still not working properly. Only after an reload of the page the block has 
the right shape. But this is maybe my fault or another issue.

best regards
Marc Wollenweber

Original issue reported on code.google.com by borntob...@googlemail.com on 19 Dec 2012 at 9:43

GoogleCodeExporter commented 8 years ago
Dear all,

I already solved it for my special purposes.  

I just store the actual mutator variable values (e.g. itemCount_, etc.) into a 
separated list (or variable in general), change the mutator variable (e.g. 
itemCount_) as required, call mutationToDom() and reverse the process 
previously performed. I put all the old values stored in the list back into 
place. Only after that domToMutation() is called and the block is mutated as 
expected.

Since the problem is solved there is no need to change anything.
BUT it would be nice to prevent uncaught expections just because an already 
none existent input can't be deleted.  

Original comment by borntob...@googlemail.com on 19 Dec 2012 at 10:08