LoopModifier doesn't reset correctly

  ... in the unlikely case you discovered a bug, post it here.

LoopModifier doesn't reset correctly

Postby niom » Sun Nov 27, 2011 10:01 pm

Hi,

There is a bug in LoopModifier reset.

When the LoopModifier in finished the mFinished value is set to true

this will only happen if you are using a non continuous looping!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public void onModifierFinished(final IModifier<T> pModifier, final T pItem) {
  3.                 if(this.mLoopModifierListener != null) {
  4.                         this.mLoopModifierListener.onLoopFinished(this, this.mLoop, this.mLoopCount);
  5.                 }
  6.  
  7.                 if(this.mLoopCount == LOOP_CONTINUOUS) {
  8.                         this.mSecondsElapsed = 0;
  9.                         this.mModifier.reset();
  10.                 } else {
  11.                         this.mLoop++;
  12.                         if(this.mLoop >= this.mLoopCount) {
  13.                                 this.mFinished = true;
  14.                                 this.mFinishedCached = true;
  15.                                 this.onModifierFinished(pItem);
  16.                         } else {
  17.                                 this.mSecondsElapsed = 0;
  18.                                 this.mModifier.reset();
  19.                         }
  20.                 }
  21.         }
  22.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


when reset is called:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public void reset() {
  3.                 this.mLoop = 0;
  4.                 this.mSecondsElapsed = 0;
  5.                 this.mModifierStartedCalled = false;
  6.  
  7.                 this.mModifier.reset();
  8.         }
  9.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


this.mFinished not reseted here.

So after the LoopModifier is finished, it cannot be restarted anymore and the onUpdate method in the LoopModifier will continue to think that the LoopModifier is finished and returns 0

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public float onUpdate(final float pSecondsElapsed, final T pItem) {
  3.                 if(this.mFinished){
  4.                         return 0;
  5.                 } else {
  6.                         float secondsElapsedRemaining = pSecondsElapsed;
  7.  
  8.                         this.mFinishedCached = false;
  9.                         while(secondsElapsedRemaining > 0 && !this.mFinishedCached) {
  10.                                 secondsElapsedRemaining -= this.mModifier.onUpdate(secondsElapsedRemaining, pItem);
  11.                         }
  12.                         this.mFinishedCached = false;
  13.  
  14.                         final float secondsElapsedUsed = pSecondsElapsed - secondsElapsedRemaining;
  15.                         this.mSecondsElapsed += secondsElapsedUsed;
  16.                         return secondsElapsedUsed;
  17.                 }
  18.         }
  19.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


So before this is fixed. You can do the following workaround to solve this:

When creating the LoopEntityModifier or LoopModifier, override the reset method when creating the instance:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. new LoopEntityModifier(/*With something to loop for*/){
  2.    @Override
  3.    public void reset(){
  4.       super.reset();
  5.       this.mFinished = false;
  6.    }
  7. };
  8.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4
niom
 
Posts: 3
Joined: Sun Jul 10, 2011 7:10 pm

Re: LoopModifier doesn't reset correctly

Postby yatuor » Fri Nov 02, 2012 9:30 am

thanks man, this saved me once
yatuor
 
Posts: 10
Joined: Sat Aug 06, 2011 10:23 am


Return to Bugs

Who is online

Users browsing this forum: No registered users and 5 guests