Show
Ignore:
Timestamp:
02/23/11 23:52:01 (4 years ago)
Author:
cedricpinson
Message:

Cedric Pinson: Fix divide by zero when Action has 0 frames, and add a warning message because it means something wrong on input data

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgAnimation/Action.cpp

    r11009 r12191  
    6565bool osgAnimation::Action::evaluateFrame(unsigned int frame, unsigned int& resultframe, unsigned int& nbloop ) 
    6666{ 
    67     nbloop = frame / getNumFrames(); 
     67    unsigned int nbFrames = getNumFrames(); 
     68    if (!nbFrames) { 
     69        nbFrames = 1; 
     70        osg::notify(osg::WARN) << "osgAnimation::Action::evaluateFrame your action " << getName() << " has 0 frames, it seems like an error in the data" << std::endl; 
     71    } 
     72 
     73    nbloop = frame / nbFrames; 
    6874    resultframe = frame; 
    6975 
    70     if (frame > getNumFrames()-1) 
     76    if (frame > nbFrames-1) 
    7177    { 
    7278        if (!getLoop()) 
    73             resultframe = frame % getNumFrames(); 
     79            resultframe = frame % nbFrames; 
    7480        else 
    7581        { 
     
    7783                return false; 
    7884            else 
    79                 resultframe = frame % getNumFrames(); 
     85                resultframe = frame % nbFrames; 
    8086        } 
    8187    }