Show
Ignore:
Timestamp:
04/13/09 11:35:52 (4 years ago)
Author:
robert
Message:

From Santosh Gaikwad, "I have added the exception handling in ply loader. All exceptions I am catching in VertexData::readPlyFile() and made sure that application will not crash or exit if any exception occurred. I am returning NULL from VertexData::readPlyFile() if any exception occurred.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/ply/vertexData.cpp

    r10012 r10040  
    158158    float   version; 
    159159    bool    result = false; 
    160     int        nComments; 
    161     char**    comments; 
    162      
    163     PlyFile* file = ply_open_for_reading( const_cast< char* >( filename ),  
     160    int     nComments; 
     161    char**  comments; 
     162     
     163    PlyFile* file = NULL; 
     164 
     165    // Try to open ply file as for reading 
     166    try{ 
     167            file  = ply_open_for_reading( const_cast< char* >( filename ),  
    164168                                          &nPlyElems, &elemNames,  
    165169                                          &fileType, &version ); 
     170    } 
     171    // Catch the if any exception thrown 
     172    catch( exception& e ) 
     173    { 
     174        MESHERROR << "Unable to read PLY file, an exception occured:  "  
     175                    << e.what() << endl; 
     176    } 
    166177 
    167178    if( !file ) 
     
    173184 
    174185    MESHASSERT( elemNames != 0 ); 
     186     
    175187 
    176188    nComments = file->num_comments; 
     
    196208        int nProps; 
    197209         
    198         PlyProperty** props = ply_get_element_description( file, elemNames[i],  
    199                                                            &nElems, &nProps ); 
     210        PlyProperty** props = NULL; 
     211        try{ 
     212                props = ply_get_element_description( file, elemNames[i],  
     213                                                     &nElems, &nProps ); 
     214        } 
     215        catch( exception& e ) 
     216        { 
     217            MESHERROR << "Unable to get PLY file description, an exception occured:  "  
     218                        << e.what() << endl; 
     219        } 
    200220        MESHASSERT( props != 0 ); 
    201221         
     
    222242            if( ignoreColors ) 
    223243                MESHINFO << "Colors in PLY file ignored per request." << endl; 
    224              
    225             // Read vertices and store in a std::vector array 
    226             readVertices( file, nElems, hasColors && !ignoreColors ); 
    227             // Check whether all vertices are loaded or not 
    228             MESHASSERT( _vertices->size() == static_cast< size_t >( nElems ) ); 
    229             // Check all color elements read or not 
    230             if( hasColors && !ignoreColors ) 
    231                 MESHASSERT( _colors->size() == static_cast< size_t >( nElems ) ); 
     244          
     245            try {    
     246                // Read vertices and store in a std::vector array 
     247                readVertices( file, nElems, hasColors && !ignoreColors ); 
     248                // Check whether all vertices are loaded or not 
     249                MESHASSERT( _vertices->size() == static_cast< size_t >( nElems ) ); 
     250                // Check all color elements read or not 
     251                if( hasColors && !ignoreColors ) 
     252                    MESHASSERT( _colors->size() == static_cast< size_t >( nElems ) ); 
     253            } 
     254            catch( exception& e ) 
     255            { 
     256                MESHERROR << "Unable to read vertex in PLY file, an exception occured:  "  
     257                            << e.what() << endl; 
     258                // stop for loop by setting the loop variable to break condition 
     259                // this way resources still get released even on error cases 
     260                i = nPlyElems; 
     261                 
     262            } 
    232263        } 
    233264        // If the string is face means triangle info started