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

Concurrent modification exceptions thrown when dynamically removing or adding controllers #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/controlP5/ControllerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public T setPosition( float[] thePosition ) {
return me;
}

public T updateAbsolutePosition( ) {
public synchronized T updateAbsolutePosition( ) {
set( absolutePosition , x( position ) , y( position ) );
set( absolutePosition , x( absolutePosition ) + x( _myParent.getAbsolutePosition( ) ) , y( absolutePosition ) + y( _myParent.getAbsolutePosition( ) ) );
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
Expand All @@ -275,7 +275,7 @@ public T updateAbsolutePosition( ) {
return me;
}

@ControlP5.Invisible public void continuousUpdateEvents( ) {
@ControlP5.Invisible synchronized public void continuousUpdateEvents( ) {
if ( controllers.size( ) <= 0 ) {
return;
}
Expand All @@ -284,7 +284,7 @@ public T updateAbsolutePosition( ) {
}
}

public T update( ) {
public synchronized T update( ) {
if ( controllers.size( ) <= 0 ) {
return me;
}
Expand All @@ -299,7 +299,7 @@ public T update( ) {
/**
* enables or disables the update function of a controller.
*/
@Override public T setUpdate( boolean theFlag ) {
@Override synchronized public T setUpdate( boolean theFlag ) {
isUpdate = theFlag;
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
( ( ControllerInterface< ? > ) controllers.get( i ) ).setUpdate( theFlag );
Expand All @@ -314,7 +314,7 @@ public boolean isUpdate( ) {
return isUpdate;
}

@ControlP5.Invisible public T updateEvents( ) {
@ControlP5.Invisible synchronized public T updateEvents( ) {
if ( isOpen ) {
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
( ( ControllerInterface< ? > ) controllers.get( i ) ).updateEvents( );
Expand Down Expand Up @@ -364,7 +364,7 @@ public boolean isMouseOver( ) {
return mouseover;
}

public T setMouseOver( boolean theFlag ) {
public synchronized T setMouseOver( boolean theFlag ) {

mouseover = ( !isBarVisible ) ? false : theFlag;

Expand All @@ -383,7 +383,7 @@ public T setMouseOver( boolean theFlag ) {
return me;
}

@ControlP5.Invisible public final void draw( PGraphics theGraphics ) {
@ControlP5.Invisible public synchronized final void draw( PGraphics theGraphics ) {
if ( isVisible ) {
theGraphics.pushMatrix( );
theGraphics.translate( x( position ) , y( position ) );
Expand All @@ -397,7 +397,7 @@ public T setMouseOver( boolean theFlag ) {
}
}

protected void drawControllers( PApplet theApplet , PGraphics theGraphics ) {
protected synchronized void drawControllers( PApplet theApplet , PGraphics theGraphics ) {
if ( isOpen ) {

for ( Canvas cc : _myCanvas ) {
Expand Down Expand Up @@ -451,7 +451,7 @@ public T removeCanvas( Canvas theCanvas ) {
/**
* Adds a controller to the group, but use Controller.setGroup() instead.
*/
public T add( ControllerInterface< ? > theElement ) {
public synchronized T add( ControllerInterface< ? > theElement ) {
controllers.add( theElement );
return me;
}
Expand All @@ -460,7 +460,7 @@ public T add( ControllerInterface< ? > theElement ) {
return bringToFront( this );
}

@Override public T bringToFront( ControllerInterface< ? > theController ) {
@Override public synchronized T bringToFront( ControllerInterface< ? > theController ) {
if ( _myParent instanceof Tab ) {
moveTo( ( Tab ) _myParent );
} else {
Expand All @@ -479,28 +479,28 @@ public T add( ControllerInterface< ? > theElement ) {
* Removes a controller from the group, but use Controller.setGroup() instead.
*/

public T remove( ControllerInterface< ? > theElement ) {
public synchronized T remove( ControllerInterface< ? > theElement ) {
if ( theElement != null ) {
theElement.setMouseOver( false );
}
controllers.remove( theElement );
return me;
}

@ControlP5.Invisible public T addDrawable( CDrawable theElement ) {
@ControlP5.Invisible synchronized public T addDrawable( CDrawable theElement ) {
controllers.addDrawable( theElement );
return me;
}

public T remove( CDrawable theElement ) {
public synchronized T remove( CDrawable theElement ) {
controllers.removeDrawable( theElement );
return me;
}

/**
* removes the group from controlP5.
*/
public void remove( ) {
public synchronized void remove( ) {
cp5.getWindow( ).removeMouseOverFor( this );
if ( _myParent != null ) {
_myParent.remove( this );
Expand Down Expand Up @@ -539,13 +539,13 @@ public ControlWindow getWindow( ) {
return cp5.getWindow( );
}

@ControlP5.Invisible public void keyEvent( KeyEvent theEvent ) {
@ControlP5.Invisible public synchronized void keyEvent( KeyEvent theEvent ) {
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
( ( ControllerInterface< ? > ) controllers.get( i ) ).keyEvent( theEvent );
}
}

public boolean setMousePressed( boolean theStatus ) {
public synchronized boolean setMousePressed( boolean theStatus ) {
if ( !isVisible ) {
return false;
}
Expand Down Expand Up @@ -593,38 +593,38 @@ public int getId( ) {
return _myId;
}

public T setColor( CColor theColor ) {
public synchronized T setColor( CColor theColor ) {
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColor( theColor );
}
return me;
}

public T setColorActive( int theColor ) {
public synchronized T setColorActive( int theColor ) {
color.setActive( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorActive( theColor );
}
return me;
}

public T setColorForeground( int theColor ) {
public synchronized T setColorForeground( int theColor ) {
color.setForeground( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorForeground( theColor );
}
return me;
}

public T setColorBackground( int theColor ) {
public synchronized T setColorBackground( int theColor ) {
color.setBackground( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorBackground( theColor );
}
return me;
}

public T setColorLabel( int theColor ) {
public synchronized T setColorLabel( int theColor ) {
color.setCaptionLabel( theColor );
if ( _myLabel != null ) {
_myLabel.setColor( color.getCaptionLabel( ) );
Expand All @@ -635,7 +635,7 @@ public T setColorLabel( int theColor ) {
return me;
}

public T setColorValue( int theColor ) {
public synchronized T setColorValue( int theColor ) {
color.setValueLabel( theColor );
if ( _myValueLabel != null ) {
_myValueLabel.setColor( color.getValueLabel( ) );
Expand Down