IronBlock icon indicating copy to clipboard operation
IronBlock copied to clipboard

Stuck and doesn't work

Open VladislavAntonyuk opened this issue 3 years ago • 10 comments

The simple program hangs and doesn't output any result image

VladislavAntonyuk avatar Jul 20 '22 08:07 VladislavAntonyuk

Thank you for reporting this.

I have attempted to reproduce this fault with this PR: #57 but the test works successfully.

Please feel free to alter the XML in the unit test to demonstrate the fault.

richorama avatar Jul 20 '22 09:07 richorama

  1. open https://richorama.github.io/IronBlock/
  2. add print n command before set n like on screenshot
  3. Click run button

VladislavAntonyuk avatar Jul 20 '22 09:07 VladislavAntonyuk

@richorama do you know why it may happen? Any chance to get it fixed?

VladislavAntonyuk avatar Aug 21 '22 15:08 VladislavAntonyuk

Yep, something is not quite right... image

henrikx avatar Sep 21 '22 13:09 henrikx

i got the same problem. i changed the code and it works

q383186554 avatar Oct 21 '22 14:10 q383186554

@q383186554 what change did you make?

richorama avatar Oct 21 '22 15:10 richorama

    public Workspace Parse(string xml, bool preserveWhitespace = false)
    {
        CustomPrintBlock.Text.Clear();
        var xdoc = new XmlDocument { PreserveWhitespace = preserveWhitespace };
        xdoc.LoadXml(xml);

        var workspace = new Workspace();
        foreach (XmlNode node in xdoc.DocumentElement.ChildNodes)
        {
            if (node.LocalName == "block" || node.LocalName == "shadow")
            {
                var block = ParseBlock(node);
                if (null != block) workspace.Blocks.Add(block);
            }
            else
            {
                // Fast-Solution :-)
                // Global variables should be parsed, else the assessment of any global variable in the script will cause an Application Exception("unexpected value type") exception. 

                // only global variables should be parsed in this context.  
                if (node.LocalName != "variables" || node.FirstChild == null ||
                    string.IsNullOrWhiteSpace(node.FirstChild.InnerText))
                    continue;

                var block = new GlobalVariablesSet();
                foreach (XmlNode nodeChild in node.ChildNodes)
                {
                    if (nodeChild.LocalName != "variable" ||
                        string.IsNullOrWhiteSpace(nodeChild.InnerText))
                        continue;

                    // Generate variable members    

                    var field = new Field
                    {
                        Name = "VAR",
                        Value = nodeChild.InnerText,
                    };

                    block.Fields.Add(field);

                    var value = new Value
                    {
                        Name = "VALUE"
                    };

                    block.Values.Add(value);


                }
                workspace.Blocks.Add(block);
            }
        }

        return workspace;
    }

    IBlock ParseBlock(XmlNode node)
    {
        if (bool.Parse(node.GetAttribute("disabled") ?? "false")) return null;

        var type = node.GetAttribute("type");
        if (!blocks.ContainsKey(type)) throw new ApplicationException($"block type not registered: '{type}'");
        // 
        var block = blocks[type]();
        if (type == "text_print")
        {
            block = new Blocks.CustomPrintBlock();
        }

        block.Type = type;
        block.Id = node.GetAttribute("id");

        foreach (XmlNode childNode in node.ChildNodes)
        {
            switch (childNode.LocalName)
            {
                case "mutation":
                    ParseMutation(childNode, block);
                    break;
                case "field":
                    ParseField(childNode, block);
                    break;
                case "value":
                    ParseValue(childNode, block);
                    break;
                case "statement":
                    ParseStatement(childNode, block);
                    break;
                case "comment":
                    ParseComment(childNode, block);
                    break;
                case "next":
                    var nextBlock = ParseBlock(childNode.FirstChild);
                    if (null != nextBlock) block.Next = nextBlock;
                    break;
                default:
                    throw new ArgumentException($"unknown xml type: {childNode.LocalName}");
            }
        }
        return block;
    }

q383186554 avatar Oct 22 '22 01:10 q383186554

@q383186554 what change did you make?

Can you see the code?

q383186554 avatar Oct 25 '22 06:10 q383186554

yes, thank you, I did see the code, and compared it to the existing code. I think it adds some block-specific logic into functions which should be agnostic of block types, so it's not a generalised solution. I also don't see how it fixes the problem :¬/

richorama avatar Oct 25 '22 08:10 richorama

I fixed the CustomPrintBlock bug. when we dag two print moudle. The output info is always the same.

yes, thank you, I did see the code, and compared it to the existing code. I think it adds some block-specific logic into functions which should be agnostic of block types, so it's not a generalised solution. I also don't see how it fixes the problem :¬/

I fixed the CustomPrintBlock bug. when we dag two print moudle. The output info is always the same.

q383186554 avatar Oct 25 '22 11:10 q383186554