[solved] Gettinge multiple istances of the same Control type

I have this code:

        for (int i = 0; i < X; i++) {
            node.addControl(new MyControl(i));
}

//after a while...

        for (int i=0;i<spatial.getNumControls();i++) {
            ((MyControl)spatial.getControl(i)).setEnabled(false);
        }

Only the first istance of MyControl gets the setEnabled() call. I suspect this is a bug… (JME 3.1)

The internal code seems to be fine, I would check first if the for is being iterated X times. After that, I would check (system.out can do it) the hashcodes of the controls (when adding and when disabling them).

1 Like

The adding is iterated, but when I disable them I only get the hashcode of the first… must check further.

OK, it goes like this:

int i=0;
how many controls are active? 2!
control[i].setEnabled(false);
i++
how many controls are active? 1!
i==1, therefore job done!

TL;DR: cycle from top and go to bottom :stuck_out_tongue:

Oh wait… it is actually my fault! I’ve overridden setEnabled to also remove the control :cold_sweat:

2 Likes

You are doing a couple weird things… and those added up to problems. :slight_smile:

Weird thing one:
-multiple controls of the same type

Weird thing two:
-having a “setter” also have odd side-effects with attachment.

Glad you got it worked out, though.

This is for sprite batching. Each control is actually dealing with a quad inside the vertex buffer.

This is to make sure that the control goes away and don’t clutter the batched node (whose quads will be reused with newer controls)