Extension fails to return control to NetLogo App 6.1.0

19 views
Skip to first unread message

Sven Anderson

unread,
Sep 30, 2019, 12:03:30 PM9/30/19
to netlogo-devel

I've added a large number of additional functions (in Java) to the original Sound extension to support visual music composition.  When I call a regular NetLogo method, setup, within which I call clear-all and my own sound:init() method which modifies the world's size, draws various lines, and adds a set of time-locked Turtles to represent drums and voices, I find that all code in sound:init() completes, but the call does not return, as if there were some infinite loop or recursion.  If, however, I first call my sound:init() from the Command Center, then there is no problem using the setup command later.

I'm having a hard time debugging this and was wondering if these symptoms indicate the nature of my error?

Thanks!

Sven Anderson

unread,
Oct 1, 2019, 1:42:01 PM10/1/19
to netlogo-devel
I was able to pinpoint that it is due to a later custom command that changes PATCHSIZE.  I have enough to probably solve this myself.  Sorry!

Jeremy Baker

unread,
Oct 1, 2019, 2:31:48 PM10/1/19
to netlogo-devel
Sven,

Thank you for the update, glad you got your problem resolved.  Feel free to reach back out if you have any other issues, it sounds like a very interesting extension!

-Jeremy

Sven Anderson

unread,
Oct 1, 2019, 5:05:48 PM10/1/19
to netlogo-devel
I have isolated the problem and recognize that it results because I don't know how to resize the world.  I decided to resize patches in my extension, which also involves rescaling drawings that I place over the world (guidelines for measures and music voices).

Here is how I have attempted to resize the world after I have changed P.PATCHSIZE or its pycor.  This appears to disappear (infinite recursion?) in ws.setDimensions().  Is there a more standard way to resize the world within an extension?  I've seen some ideas in ImporterJ.java, but have not yet got these to work.    Thanks!

 
    public static void resizeWorld(Context context)
            throws ExtensionException {

        ExtensionContext ec = (ExtensionContext) context;
        Workspace ws = ec.workspace();
        ws.setDimensions(new
                        WorldDimensions3D(0, P.XMAX - 1, 0,
                        P.YMAX, 0, 1,
                        P.PATCHSIZE,
                        P.WRAP, P.WRAP, P.WRAP),
                P.PATCHSIZE);
        World w = ws.world();

        // w.patchSize(P.PATCHSIZE);
        //ws.resizeView();  // not in event thread
        //ws.setDimensions(w.getDimensions(), P.PATCHSIZE);

        int pcoloridx = getPcolorID(w);

        initDrawing(w, ec);
        updateAgentsPositions(w);

Jeremy Baker

unread,
Oct 3, 2019, 11:58:44 AM10/3/19
to netlogo-devel

Hey Sven,


If you need to recreate some functionality from an existing core primitive, the easiest way would be to check out the code in the NetLogo code. Prim files and classes are prefixed with an underscore, so usually aren't too hard to find.


In this case the _resizeworld code and _setpatchsize code look pretty close to what you're doing, but they are wrapping the setDimensions() call in a waitFor(). I believe this is because the setDimensions() method is running the change on an event queue for the GUI. That might cause the weird behavior you're seeing, so it'd be worth trying the same waitFor() call to see if it helps.


-Jeremy

Sven Anderson

unread,
Oct 3, 2019, 3:19:55 PM10/3/19
to netlogo-devel

Jeremy,

Many thanks, that was exactly the information that I needed.  Knowing where to find the primitives was new to me and very helpful.  Running within the event queue was exactly th right fix.


On Monday, September 30, 2019 at 12:03:30 PM UTC-4, Sven Anderson wrote:
Reply all
Reply to author
Forward
0 new messages