Changeset 403 for trunk/src


Ignore:
Timestamp:
06/14/15 14:31:00 (10 years ago)
Author:
epyon
Message:
  • got rid of exceptions
  • assert enhancements
  • lots of minor cleanup
Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/library.cc

    r402 r403  
    4444        {
    4545                m_handle = nullptr;
    46                 NV_THROW( library_error, "Can't load library!", name.data() );
     46                NV_LOG_CRITICAL( "library \"", name, "\" : failed to load!" );
     47                NV_ABORT( "Can't load library!" );
    4748        }
    4849}
     
    7071        return true;
    7172    }
    72     NV_LOG_NOTICE( "library : loading '", m_name, "'..." );
     73    NV_LOG_NOTICE( "library \"", string_view( m_name ), "\" : loading..." );
    7374
    7475        std::string name = m_name;
     
    8485    if ( m_handle == NULL )
    8586    {
    86                 NV_LOG_NOTICE( "library : '", name, "' failed to open." );
     87                NV_LOG_NOTICE( "library \"", string_view( name ), "\" : failed to open!" );
    8788                return false;
    8889    }
    89     NV_LOG_NOTICE( "library : '", name, "' loaded." );
     90    NV_LOG_NOTICE( "library \"", string_view( name ), "\" : loaded." );
    9091        return true;
    9192}
     
    9697    if ( !result )
    9798    {
    98         NV_THROW( library_error, "Can't find symbol " + std::string(symbol.data(),symbol.size()) + "!", m_name );
     99                NV_LOG_CRITICAL( "library \"", string_view( m_name ), "\" : can't find symbol \"", symbol, "\"" );
     100                NV_ABORT( "Library symbol load failed!" );
    99101    }
    100102        return result;
     
    115117    if ( ! NV_LIB_CLOSE( m_handle ) )
    116118    {
    117         NV_LOG_ERROR( "library : can't close library '", m_name, "'!" );
     119        NV_LOG_ERROR( "library \"", string_view( m_name ), "\" : can't close library!" );
    118120    }
    119121    m_handle = nullptr;
  • trunk/src/gfx/texture_font.cc

    r399 r403  
    1111
    1212using namespace nv;
     13
     14#define NV_CHECK_FREETYPE_ERROR( error, ... ) \
     15if ( error != 0 ) { \
     16        NV_LOG_CRITICAL( "freetype : ", __VA_ARGS__ ); \
     17        NV_ABORT( "freetype : freetype library error!" ); \
     18}
    1319
    1420texture_glyph::texture_glyph()
     
    4551         
    4652        error = FT_Init_FreeType( (FT_Library*)(&m_rlibrary) );
    47         if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
     53        NV_CHECK_FREETYPE_ERROR( error, "error on FT_Init_FreeType, code - ", error );
    4854
    4955        error = FT_New_Face( (FT_Library)(m_rlibrary), filename, 0, (FT_Face*)(&m_rface) );
    50         if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
     56        NV_CHECK_FREETYPE_ERROR( error, "error on FT_New_Face, code - ", error );
    5157
    5258        error = FT_Set_Char_Size( (FT_Face)(m_rface), (int)(size*64), 0, 72*64, 72 );
    53         if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
     59        NV_CHECK_FREETYPE_ERROR( error, "error on FT_Set_Char_Size, code - ", error );
    5460
    5561    FT_Set_Transform( (FT_Face)(m_rface), &matrix, NULL );
     
    123129                FT_UInt glyph_index = FT_Get_Char_Index( face, c );
    124130                FT_Error error = FT_Load_Glyph( face, glyph_index, flags );
    125                 if ( error )
    126                 {
    127                         NV_LOG_ERROR( "FT_Error while loading glyphs, error: ", error, " code: ", c );
    128                         NV_THROW( std::runtime_error, "FT_Error while loading glyphs" );
    129                 }
     131                NV_CHECK_FREETYPE_ERROR( error, "error on FT_Load_Glyph, gylph '", c ,"' code - ", error );
    130132
    131133                FT_GlyphSlot slot   = face->glyph;
     
    141143                if ( r.pos.x < 0 )
    142144                {
    143                         NV_LOG_ERROR( "Atlas full while loading glyphs, r.pos.x: ", r.pos.x, " code: ", c );
    144                         NV_THROW( std::runtime_error, "Atlas full while loading glyphs" );
     145                        NV_LOG_CRITICAL( "texture_font : atlas full while loading glyphs, gylph '", c, "' r.pos.x = ", r.pos.x );
     146                        NV_ABORT( "texture_font : atlas full while loading gylphs!" );
    145147                }
    146148                if (depth == 4)
  • trunk/src/gl/gl_context.cc

    r398 r403  
    379379void gl_context::set_viewport( const ivec4& viewport )
    380380{
    381         if ( viewport.z < 0 || viewport.w < 0 )
    382         {
    383                 NV_THROW( logic_error, "viewport width and height must be greater than zero!");
    384         }
    385 
     381        NV_ASSERT_ALWAYS( viewport.z > 0 && viewport.w > 0, "viewport dimensions must be greater than zero!" );
    386382        m_viewport = viewport;
    387383        glViewport( viewport.x, viewport.y, viewport.z, viewport.w );
     
    456452        }
    457453
    458         if ( scissor.dim.x < 0 || scissor.dim.y < 0 )
    459         {
    460                 NV_THROW( logic_error, "scissor_test.rect width and height must be greater than zero!" );
    461         }
    462454
    463455        if ( scissor.enabled )
    464456        {
     457                NV_ASSERT_ALWAYS( scissor.dim.x > 0 && scissor.dim.y > 0, "scissor_test.rect dimension equal to zero!" );
     458
    465459                if ( m_render_state.scissor_test.dim != scissor.dim || m_render_state.scissor_test.pos != scissor.pos )
    466460                {
     
    514508void gl_context::apply_depth_range( const depth_range& range )
    515509{
    516         if ( range.near < 0.0 || range.near > 1.0 )
    517         {
    518                 NV_THROW( logic_error, "render_state.depth_range.near must be between zero and one!");
    519         }
    520         if ( range.far < 0.0 || range.far > 1.0 )
    521         {
    522                 NV_THROW( logic_error, "render_state.depth_range.far must be between zero and one!");
    523         }
     510        NV_ASSERT_ALWAYS( range.near >= 0.0 && range.near <= 1.0, "render_state.depth_range.near must be between zero and one!" );
     511        NV_ASSERT_ALWAYS( range.far  >= 0.0 && range.far  <= 1.0, "render_state.depth_range.far must be between zero and one!" );
    524512
    525513        if ((m_render_state.depth_range.far  != range.far) ||
  • trunk/src/gl/gl_device.cc

    r399 r403  
    238238                if ( fatal )
    239239                {
    240                         NV_LOG_ERROR( "Uniform '", name, "' not found in program!" );
    241                         NV_THROW( runtime_error, ( "Uniform '"+name+"' not found!" ) );
     240                        NV_LOG_CRITICAL( "gl_device : uniform '", string_view( name ), "' not found in program!" );
     241                        NV_ABORT( "gl_device : uniform not found!" );
    242242                }
    243243        }
     
    257257                if ( fatal )
    258258                {
    259                         NV_LOG_ERROR( "Attribute '", name, "' not found in program!" );
    260                         NV_THROW( runtime_error, ( "Attribute '"+ name + "' not found!" ) );
     259                        NV_LOG_CRITICAL( "gl_device : attribute '", string_view( name ), "' not found in program!" );
     260                        NV_ABORT( "gl_device : attribute not found!" );
    261261                }
    262262        }
  • trunk/src/lua/lua_state.cc

    r399 r403  
    1515
    1616// stack_guard
     17
     18#define NV_LUA_ABORT( func, ... ) \
     19        NV_LOG_CRITICAL( "lua::" func " : ", __VA_ARGS__ ) \
     20        NV_ABORT( "lua::" func " : critical error!" )
     21
    1722
    1823lua::stack_guard::stack_guard( lua::state* aL )
     
    424429        if ( lua_isnil( m_state, -1 ) )
    425430        {
    426                 NV_THROW( runtime_error, lua_name.to_string() + " type not registered!" );
     431                NV_LUA_ABORT( "state::register_object", lua_name, " type not registered!" );
    427432        }
    428433        deep_pointer_copy( -1, o );
     
    436441        if ( lua_isnil( m_state, -1 ) )
    437442        {
    438                 NV_THROW( runtime_error, storage.to_string() + " storage not registered!" );
     443                NV_LUA_ABORT( "state::register_proto", "\"", storage, "\" storage not registered!" );
    439444        }
    440445        lua_getfield( m_state, -1, id.data() );
    441446        if ( lua_isnil( m_state, -1 ) )
    442447        {
    443                 NV_THROW( runtime_error, id.to_string() + " not found in " + storage.to_string() + " storage!" );
     448                NV_LUA_ABORT( "state::register_proto", "\"", id, "\" not found in \"", storage, "\"!" );
    444449        }
    445450        return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) );
     
    452457        if ( lua_isnil( m_state, -1 ) )
    453458        {
    454                 NV_THROW( runtime_error, lua_name.to_string() + " type not registered!" );
     459                NV_LUA_ABORT( "state::register_native_object_method", "\"", lua_name, "\" type not registered!" );
    455460        }
    456461        lua_pushcfunction( m_state, f );
     
    502507        if ( has_functions || has_metatable )
    503508        {
    504                 lua_pushstring( m_state, "__ptr" );
     509                lua_pushliteral( m_state, "__ptr" );
    505510                lua_pushlightuserdata( m_state, obj );
    506511                lua_rawset( m_state, -3 );
     
    569574        if ( lua_isnil( m_state, -1 ) )
    570575        {
    571                 NV_THROW( runtime_error, name.to_string() + " type not registered!" );
     576                NV_LUA_ABORT( "state::register_singleton", "\"", name, "\" type not registered!" );
    572577        }
    573578        deep_pointer_copy( -1, o );
  • trunk/src/stl/assert.cc

    r402 r403  
    99#include "nv/base/assert.hh"
    1010#undef NV_BASE_COMMON_HH
     11#include "nv/core/logging.hh"
    1112
     13extern "C" {
    1214#if NV_COMPILER == NV_MSVC
     15        NV_NORETURN void __cdecl exit( _In_ int _Code );
     16#else
     17        void exit( int status_code ) NV_NORETURN;
     18#endif
     19}
    1320
    14 #       if NV_DEBUG
    15 
     21#if NV_DEBUG
     22#       if NV_COMPILER == NV_MSVC
    1623extern "C" {
    1724        void __cdecl _wassert( const wchar_t * _Message, const wchar_t *_File, unsigned _Line );
    1825}
    1926
    20 void nv_internal_assert( const wchar_t * message, const wchar_t* file, unsigned line )
     27void nv::detail::assert_fail( const wchar_t * message, const wchar_t* file, unsigned line )
    2128{
    2229        _wassert( message, file, line );
    2330}
    24 #       else 
    25         void nv_internal_assert( const wchar_t *, const wchar_t*, unsigned ) {}
    26 #       endif  // NV_DEBUG
    27 #else // NV_COMPILER
    28 
    29 #       if NV_DEBUG
     31#       else // NV_COMPILER
    3032#       if NV_COMPILER == NV_CLANG
    3133extern "C" {
    32         extern void __assert(const char *, const char *, unsigned int, const char *)
    33                 __attribute__ ((__noreturn__));
     34        extern void __assert(const char *, const char *, unsigned int, const char *) NV_NORETURN;
    3435}
     36#define NV_ASSERT_IMPL __assert
    3537#       else
    3638extern "C" {
    37         extern void __assert_fail(const char *, const char *, unsigned int, const char *)
    38                 __attribute__ ((__noreturn__));
     39        extern void __assert_fail(const char *, const char *, unsigned int, const char *) NV_NORETURN;
    3940}
     41#define NV_ASSERT_IMPL __assert_fail
    4042#       endif
    41 __attribute__( ( __noreturn__ ) ) void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function )
     43NV_NORETURN void nv::detail::assert_fail( const char * assertion, const char * file, unsigned int line, const char * function )
    4244{
    43 #       if NV_COMPILER == NV_CLANG
    44         __assert(assertion, file, line, function );
    45 #       else
    46         __assert_fail(assertion, file, line, function );
    47 #       endif
    48 }
    49 #       else
    50 void nv_internal_assert( const char * , const char * , unsigned int , const char * )
    51 {
     45        NV_ASSERT_IMPL (assertion, file, line, function );
    5246}
    5347#       endif
    5448
    55 #endif // NV_COMPILER
     49#endif // NV_DEBUG
    5650
     51NV_NORETURN void nv::detail::abort( const char * msg, const char * file, unsigned int line, const char * function )
     52{
     53        NV_LOG_CRITICAL( "Abort called : ", msg );
     54        NV_LOG_CRITICAL( "  in ", file, ":", line, " (", function, ")" );
     55        NV_LOG_CRITICAL( "Aborting..." );
     56        exit( 1 );
     57}
     58
     59NV_NORETURN void nv::detail::assert_abort( const char * msg, const char * file, unsigned int line, const char * function )
     60{
     61        NV_LOG_CRITICAL( "Assertion failed: (", msg, ")" );
     62        NV_LOG_CRITICAL( "  in ", file, ":", line, " (", function, ")" );
     63        NV_LOG_CRITICAL( "Aborting..." );
     64        exit( 1 );
     65}
Note: See TracChangeset for help on using the changeset viewer.