Ignore:
Timestamp:
05/28/13 22:29:08 (12 years ago)
Author:
epyon
Message:
  • error checking for attribute and uniform queries
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/program.hh

    r41 r50  
    1515#include <unordered_map>
    1616#include <nv/logging.hh>
     17#include <nv/exception.hh>
    1718#include <nv/common.hh>
    1819#include <nv/string.hh>
     
    108109                                        i != m_uniform_map.end(); ++i ) delete i->second;
    109110                }
     111                attribute* try_get_attribute( const string& name ) const
     112                {
     113                        attribute_map::const_iterator i = m_attribute_map.find( name );
     114                        if ( i != m_attribute_map.end() )
     115                        {
     116                                return i->second;
     117                        }
     118                        return nullptr;
     119                }
     120
    110121                attribute* get_attribute( const string& name ) const
    111122                {
    112123                        attribute_map::const_iterator i = m_attribute_map.find( name );
    113124                        if ( i != m_attribute_map.end() )
     125                        {
     126                                return i->second;
     127                        }
     128                        NV_LOG( LOG_ERROR, "Attribute '" << name << "' not found in program!" );
     129                        throw runtime_error( "Attribute '"+name+"' not found!" );
     130                }
     131
     132                uniform_base* try_get_uniform( const string& name ) const
     133                {
     134                        uniform_map::const_iterator i = m_uniform_map.find( name );
     135                        if ( i != m_uniform_map.end() )
    114136                        {
    115137                                return i->second;
     
    125147                                return i->second;
    126148                        }
    127                         return nullptr;
     149                        NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
     150                        throw runtime_error( "Uniform '"+name+"' not found!" );
    128151                }
    129152
     
    133156                        uniform_base* base = get_uniform( name );
    134157                        // restore typechecking, but remember to accept int for float!
    135                         if ( base == nullptr /* || base->get_type() != type_to_enum<T>::type */ )
    136                         {
    137                                 NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
    138                                 return;
    139                         }
     158                        // if ( /* base->get_type() != type_to_enum<T>::type */ )
     159                        // {
     160                        //              NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
     161                        //              return;
     162                        // }
    140163                        ((uniform<T>*)( base ))->set_value( value );
    141164                }
Note: See TracChangeset for help on using the changeset viewer.