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

Calls to unregisterMethod may not work #223

Closed
processing-bot opened this issue Jul 9, 2021 · 5 comments
Closed

Calls to unregisterMethod may not work #223

processing-bot opened this issue Jul 9, 2021 · 5 comments

Comments

@processing-bot
Copy link
Collaborator

Created by: WhiteSte

I'm referring to #199, i'm using the last version (4.05a)

Description

I'm supposing that the method unregisterMethod from PApplet class is not working at all.

Expected Behavior

After loading a method inside PApplet it should be removed.

Current Behavior

Methods seems to me that are not removed.

Steps to Reproduce

SKETCH

TestObject test;
  
  void setup() {
    test = new TestObject(this, "object 1");
    test.remove();
}
  
  void draw() {
    if (frameCount == 10) {
      exit();
    }
  }

CLASS

public class TestObject {
  
    private PApplet parent;
    private String name;
    private boolean flag = false;
  
    public TestObject(PApplet parent, String name) {
      this.parent = parent;
      this.name = name;
      parent.registerMethod("post", this);
    }
  
    public void post() {
      if (flag == true) System.out.println("You should have removed this Method");
      System.out.println("Running: " + name);
      this.remove(); // That should stop spamming in console
      flag = true;
}
  public void remove(){
    System.out.println("Removing: " + name);
    parent.unregisterMethod("post", name);
  }
}

Your Environment

  • Processing version: 4.05alpha
  • Operating System and OS version: Mac os latest version Big Sur 11.4
  • Other information:

Possible Causes / Solutions

I saw that a modification to this method was made some weeks ago, maybe that's the cause

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Found the problem; looking into it.

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Fixed for alpha 6.

There are a couple bugs in your test case—it's removing the name of the object not the object itself (change name to this).

public class TestObject { 
  private PApplet parent;
  private String name;
  private boolean flag = false;

  public TestObject(PApplet parent, String name) {
    this.parent = parent;
    this.name = name;
    parent.registerMethod("post", this);
  }

  public void post() {
    if (flag == true) System.out.println("You should have removed this Method");
    System.out.println("Running: " + this);
    this.remove(); // That should stop spamming in console
    flag = true;
  }
  
  public void remove() {
    System.out.println("Removing: " + this);
    parent.unregisterMethod("post", this);
  }
}

You're also removing the method before it has a chance to actually run… i.e. You're adding and then removing the post() method inside setup() before any post() calls are made, so test.remove() should be called somewhere later.

@processing-bot
Copy link
Collaborator Author

Created by: WhiteSte

Fixed for alpha 6.

There are a couple bugs in your test case—it's removing the name of the object not the object itself (change name to this).

public class TestObject { 
  private PApplet parent;
  private String name;
  private boolean flag = false;

  public TestObject(PApplet parent, String name) {
    this.parent = parent;
    this.name = name;
    parent.registerMethod("post", this);
  }

  public void post() {
    if (flag == true) System.out.println("You should have removed this Method");
    System.out.println("Running: " + this);
    this.remove(); // That should stop spamming in console
    flag = true;
  }
  
  public void remove() {
    System.out.println("Removing: " + this);
    parent.unregisterMethod("post", this);
  }
}

You're also removing the method before it has a chance to actually run… i.e. You're adding and then removing the post() method inside setup() before any post() calls are made, so test.remove() should be called somewhere later.

Yep the idea was that post() should never run because i was adding and removing at the "same time". I'm not a real programmer so it was just a demo to make the idea. Btw, thanks for the fix, do you have an idea of a date for release 6 or do you think it could work if i download the actual code and then make by myself the jar files?

@processing-bot
Copy link
Collaborator Author

Created by: benfry

Yeah, it's not a critique of your code—just trying to help.

@processing-bot
Copy link
Collaborator Author

Created by: github-actions[bot]

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant