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): unable to properly debug custom java components #1315

Open
me-nkr opened this issue Aug 11, 2024 Discussed in #1312 · 1 comment · May be fixed by #1316
Open

(bug): unable to properly debug custom java components #1315

me-nkr opened this issue Aug 11, 2024 Discussed in #1312 · 1 comment · May be fixed by #1316

Comments

@me-nkr
Copy link

me-nkr commented Aug 11, 2024

Discussed in #1312

Originally posted by me-nkr August 9, 2024
I am trying to create a custom component and debug it, and there are two issues I am facing

  • when debugging the component is greyed out
    image

    • I tried using java -cp "digitaln2t-1.0-SNAPSHOT.jar:/path/to/Digital/Digital.jar" com.github.itoshkov.digitaln2t.Nand2TetrisComponentSource, java -cp "target/pluginExample-1.0-SNAPSHOT.jar:Digital.jar" de.neemann.digital.plugin.DemoCompone ntSource and tried using vscode java debugger, the same is the result
    • it worked when I provided the jar path as Java Library option in Digital Settings
  • this is a minor inconvenience, but just wanted to know about it, when using vscode java debugger and making changes to the file the changes are not reflected in the Digital instance that was opened with debugger.

@me-nkr
Copy link
Author

me-nkr commented Aug 11, 2024

I found out why it's not working and why it worked when there was a file in file history.

It has to do with the order of executions and the following lines of code

if (builder.fileToOpen != null) {
LOGGER.debug("create with given file " + builder.fileToOpen);
SwingUtilities.invokeLater(() -> loadFile(builder.fileToOpen, builder.library == null, builder.library == null));
} else {
File name = fileHistory.getMostRecent();
LOGGER.debug("create with history file " + name);
if (name != null) {
SwingUtilities.invokeLater(() -> loadFile(name, true, false));
}

Here is a detailed explanation

The order of executions is as follows when debugging

  1. create a new element library
    a. calls the LibraryNode.traverse() method from populateNodeMap()
    b. calls the LibraryNode.traverse() method directly
    populateNodeMap();
    isProgrammable.clear();
    root.traverse(libraryNode -> {
    ElementTypeDescription d = libraryNode.getDescriptionOrNull();
    if (d != null && d.hasAttribute(Keys.BLOWN))
    isProgrammable.add(d.getName());
    });
  2. register components from custom Java components to the above-created library using the ElementLibrary.registerComponentSource() method
  3. set the above created and modified library as the library of MainBuilder using the MainBuilder.setLibrary() method
  4. then the MainBuilder.openLater() method calls the MainBuilder.build() method which in turn instantiates the Main class
  5. while instantiating the Main class, as per the first block of code linked, the LibraryNode.traverse() method is called once more as a result of calling the Main.loadFile() method which only happens if there is a file in File History

The gotcha

First two calls to the LibraryNode.traverse() method happens before the ElementLibrary.registerComponentSource() and the MainBuilder.setLibrary() method calls. Because of this, the custom Java components are not in the element library when the LibraryNode.traverse() method is called which is responsible for marking library nodes as unique. Since the custom Java components are not marked as unique, they become unusable. And since the LibraryNode.traverse() method is called once more after all this when there is a file in File History, the custom Java components become usable.

Originally posted by @me-nkr in #1312 (comment)

@me-nkr me-nkr linked a pull request Aug 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant