Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: Stack overflow with simple code #526

Closed
1 of 2 tasks
doublethink13 opened this issue Dec 5, 2024 · 11 comments
Closed
1 of 2 tasks

[bug]: Stack overflow with simple code #526

doublethink13 opened this issue Dec 5, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@doublethink13
Copy link

doublethink13 commented Dec 5, 2024

Tool

Jack Compiler

Interface

Website (https://nand2tetris.github.io/web-ide)

Contact Details

No response

What happened?

I'm compiling and running this code:

class Main {
    function void main() {
        while (true) {
            do Output.printString("Hello, world!");
            do Output.println();
            do Sys.wait(10000);
            do Screen.clearScreen();

            do Output.printString("Goodbye, world..");
            do Output.println();
            do Sys.wait(10000);
            do Screen.clearScreen();
        }

        return;
    }
}

I have two issues with it.

First, the Sys.wait(10000) instruction does not wait the expected time.

Second, the code eventually reaches a stack overflow.

See:

Recording 2024-12-05 at 21 27 44

Additional Comments

No response

Do you want to try to fix this bug?

  • I want to try to add this feature!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@doublethink13 doublethink13 added the bug Something isn't working label Dec 5, 2024
@doublethink13
Copy link
Author

Note that the following code, does not produce a stack overflow for me:

class Main {
    function void main() {
        var int test;

        while (true) {
            let test = test + 1;
            do Sys.wait(1000);
        }

        return;
    }
}

The only local variable just keeps on increasing. However, the do Sys.wait(1000) still does not work.

@doublethink13
Copy link
Author

I'll test this in the older local compiler to see if the problem persists once I have the time.

@dorianignee
Copy link
Contributor

The message "Maximum call stack size exceeded" is shown when the text cursor is past the end of the screen. I don't really know why the error occurs, because the "Output" class should just reset the row to zero, when it does a newline in the last row.

dorianignee pushed a commit to dorianignee/nand2tetris-web-ide that referenced this issue Dec 10, 2024
…ing println in last row

move check for last screen row from printChar to println, so the check runs on every newline command
@dorianignee
Copy link
Contributor

dorianignee commented Dec 10, 2024

I created a PR for the error message. The Sys.wait instruction will be fixed with PR #528.
When those two issues are fixed, there's still a problem with your code: You create new String objects with every printString command. So you will run out of heap space (ERR6) after a few thousand iterations. You could reuse your strings to avoid that problem like this:

class Main {
    function void main() {
        var String hello, goodbye;
        let hello = "Hello, world!";
        let goodbye = "Goodbye, world..";

        while (true) {
            do Output.printString(hello);
            do Output.println();
            do Sys.wait(10000);
            do Screen.clearScreen();

            do Output.printString(goodbye);
            do Output.println();
            do Sys.wait(10000);
            do Screen.clearScreen();
        }

        return;
    }
}

@doublethink13
Copy link
Author

doublethink13 commented Dec 10, 2024

Unfortunately that still does not work:

Recording 2024-12-10 at 14 29 04

@dorianignee
Copy link
Contributor

Yes, you need to wait until my PRs #529 and #528 are merged into this repo. I'm just a random guy that contributes to this project, but I can't update this repo directly. One of the maintainers needs to review and approve my changes and merge my pull requests, so that they become active on the website.
As long as this issue is open, my changes are not applied to the page.

@doublethink13
Copy link
Author

I appreciate your help! Thanks a lot :)

@doublethink13
Copy link
Author

I see that you released a new version recently but I still get an old IDE version in my browser:

image

@DavidSouther
Copy link
Collaborator

Could you paste the headers for the index.html request?

https://developer.chrome.com/blog/copy-the-response-of-a-network-resource-to-your-clipboard

@doublethink13
Copy link
Author

Now I'm getting the latest version:

image

Just for completion, here are the headers:

image

image

image

image

@doublethink13
Copy link
Author

I can also confirm this issue seems fixed:

Recording 2025-01-03 at 10 10 10

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants