Changeset 403
- Timestamp:
- 06/14/15 14:31:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/base/assert.hh
r402 r403 10 10 * @brief Assert functions 11 11 */ 12 // TODO: assert levels 13 // TODO: assert should not depend on CORE! 12 14 13 15 #ifndef NV_BASE_COMMON_HH … … 23 25 #endif 24 26 25 #if NV_COMPILER == NV_MSVC 26 void nv_internal_assert( const wchar_t * message, const wchar_t* file, unsigned line ); 27 # if NV_DEBUG 28 # define NV_ASSERT_IMPL(cond) (void)( (!!(cond)) || (nv_internal_assert(NV_WIDE(#cond), NV_WIDE(__FILE__), __LINE__), 0) ) 27 #ifdef assert 28 #undef assert 29 #endif 30 31 namespace nv 32 { 33 namespace detail 34 { 35 NV_NORETURN void abort( const char * msg, const char * file, unsigned int line, const char * function ); 36 NV_NORETURN void assert_abort( const char * msg, const char * file, unsigned int line, const char * function ); 37 #if NV_DEBUG 38 # if NV_COMPILER == NV_MSVC 39 NV_NORETURN void assert_fail( const wchar_t * message, const wchar_t* file, unsigned line ); 29 40 # else 30 # define NV_ASSERT_IMPL(cond) 31 # endif 32 #else 33 void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function ); 34 # if NV_DEBUG 35 # define NV_ASSERT_IMPL(cond) ((cond) ? static_cast<void>(0) : nv_internal_assert(NV_STRINGIZE(cond), __FILE__, __LINE__, __PRETTY_FUNCTION__)) 36 # else 37 # define NV_ASSERT_IMPL(cond) 41 NV_NORETURN void assert_fail( const char * assertion, const char * file, unsigned int line, const char * function ); 38 42 # endif 39 43 #endif 44 } 40 45 41 // TODO: assert levels 46 NV_NORETURN void exit( int ret_val ); 47 } 48 49 50 51 #define NV_ABORT( msg ) ::nv::detail::abort( msg, __FILE__, __LINE__, NV_FUNC_SIG ) 52 42 53 #if NV_DEBUG 43 #define NV_ASSERT(cond, msg) NV_ASSERT_IMPL( (cond) && "assertion failed:" msg ) 44 #define NV_DEBUG_ASSERT(cond, msg) NV_ASSERT_IMPL( (cond) && "assertion failed:" msg ) 54 # if NV_COMPILER == NV_MSVC 55 # define NV_ASSERT_COND(cond) (void)( (!!(cond)) || (::nv::detail::assert_fail(NV_WIDE(#cond), NV_WIDE(__FILE__), __LINE__), 0) ) 56 # else 57 # define NV_ASSERT_COND(cond) ((cond) ? static_cast<void>(0) : ::nv::detail::assert_fail(NV_STRINGIZE(cond), __FILE__, __LINE__, __PRETTY_FUNCTION__)) 58 # endif 59 #define NV_ASSERT(cond, msg) NV_ASSERT_COND( (cond) && "assertion failed:" msg ) 60 #define NV_ASSERT_DEBUG(cond, msg) NV_ASSERT_COND( (cond) && "assertion failed:" msg ) 61 #define NV_ASSERT_ALWAYS(cond, msg) NV_ASSERT_COND( (cond) && "assertion failed:" msg ) 45 62 #else 46 63 #define NV_ASSERT(cond, msg) ((void)0) 47 #define NV_DEBUG_ASSERT(cond, msg) ((void)0) 64 #define NV_ASSERT_DEBUG(cond, msg) ((void)0) 65 #define NV_ASSERT_ALWAYS(cond, msg) ((cond) ? static_cast<void>(0) : ::nv::detail::assert_abort(NV_STRINGIZE(cond) " " msg, __FILE__, __LINE__, NV_FUNC_SIG )) 48 66 #endif 49 67 -
trunk/nv/base/common.hh
r402 r403 128 128 129 129 #if NV_COMPILER == NV_MSVC 130 #define NV_FUNC_SIG __FUNCSIG__ 130 131 #define NV_DEPRECATED(func) __declspec(deprecated) func 132 #define NV_NORETURN __declspec(noreturn) 131 133 #define NV_NOALIAS __declspec(noalias) 132 134 #define NV_RESTRICT __declspec(restrict) … … 139 141 #endif 140 142 #elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG 143 #define NV_FUNC_SIG __PRETTY_FUNCTION__ 141 144 #define NV_DEPRECATED(func) func __attribute__ ((deprecated)) 145 #define NV_NORETURN __attribute__ ((__noreturn__)) 142 146 #define NV_RESTRICT __restrict__ 143 147 #define NV_RESTRICT_VAR __restrict__ … … 149 153 150 154 #define NV_UNUSED(x) (void)(x) 151 #define NV_THROW(eobj, ...) { \152 NV_LOG_ERROR( __FILE__ " line " NV_STRINGIZE(__LINE__) " - exception thrown - " #eobj ); \153 throw eobj( __VA_ARGS__ ); \154 }155 155 156 156 // MSVC and GCC is too stupid to notice fully covered enums, clang -
trunk/nv/core/library.hh
r402 r403 15 15 16 16 #include <nv/common.hh> 17 #include <nv/stl/exception.hh>18 17 #include <nv/stl/string.hh> 19 18 #include <string> … … 113 112 }; // class Library 114 113 115 class library_error : public runtime_error116 {117 /// Library name118 std::string m_name;119 public:120 /**121 * Constructor122 */123 library_error( const std::string& message, const std::string& name )124 : runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name )125 {126 }127 128 /**129 * Returns library name130 */131 const std::string& get_name()132 {133 return m_name;134 }135 };136 137 114 } // namespace nv 138 115 -
trunk/nv/stl/algorithm/raw.hh
r402 r403 34 34 T* raw_copy( const T* first, const T* last, T* out ) 35 35 { 36 NV_ DEBUG_ASSERT( last - first > 0, "raw_copy range fail!" );36 NV_ASSERT_DEBUG( last - first > 0, "raw_copy range fail!" ); 37 37 return static_cast<T*>( nvmemcpy( out, first, detail::byte_distance( first, last ) ) ) + ( last - first ); 38 38 } … … 47 47 T* raw_alias_copy( const T* first, const T* last, T* out ) 48 48 { 49 NV_ DEBUG_ASSERT( last - first > 0, "raw_alias_copy range fail!" );49 NV_ASSERT_DEBUG( last - first > 0, "raw_alias_copy range fail!" ); 50 50 return static_cast<T*>( nvmemmove( out, first, detail::byte_distance( first, last ) ) ) + ( last - first ); 51 51 } … … 60 60 T* raw_zero( T* first, T* last ) 61 61 { 62 NV_ DEBUG_ASSERT( last - first > 0, "raw_zero range fail!" );62 NV_ASSERT_DEBUG( last - first > 0, "raw_zero range fail!" ); 63 63 return static_cast<T*>( nvmemset( first, 0, detail::byte_distance( first, last ) ) ) + ( last - first ); 64 64 } … … 73 73 T* raw_fill( T* first, T* last, unsigned char value ) 74 74 { 75 NV_ DEBUG_ASSERT( last - first > 0, "raw_fill range fail!" );75 NV_ASSERT_DEBUG( last - first > 0, "raw_fill range fail!" ); 76 76 return static_cast<T*>( nvmemset( first, value, detail::byte_distance( first, last ) ) ) + ( last - first ); 77 77 } -
trunk/nv/stl/string.hh
r402 r403 28 28 #include <nv/stl/type_traits/primary.hh> 29 29 #include <nv/stl/memory.hh> 30 #include <nv/stl/exception.hh>31 30 #include <nv/stl/algorithm.hh> 32 31 #include <nv/stl/functional/hash.hh> -
trunk/nv/stl/unordered_map.hh
r401 r403 20 20 namespace nv 21 21 { 22 template < typename Pair > 23 struct use_first 24 { 25 typedef Pair argument_type; 26 typedef typename Pair::first_type result_type; 27 const result_type& operator()( const Pair& arg ) const 28 { 29 return arg.first; 30 } 31 }; 32 22 33 23 template < 34 24 typename Key, -
trunk/src/core/library.cc
r402 r403 44 44 { 45 45 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!" ); 47 48 } 48 49 } … … 70 71 return true; 71 72 } 72 NV_LOG_NOTICE( "library : loading '", m_name, "'..." );73 NV_LOG_NOTICE( "library \"", string_view( m_name ), "\" : loading..." ); 73 74 74 75 std::string name = m_name; … … 84 85 if ( m_handle == NULL ) 85 86 { 86 NV_LOG_NOTICE( "library : '", name, "' failed to open." );87 NV_LOG_NOTICE( "library \"", string_view( name ), "\" : failed to open!" ); 87 88 return false; 88 89 } 89 NV_LOG_NOTICE( "library : '", name, "'loaded." );90 NV_LOG_NOTICE( "library \"", string_view( name ), "\" : loaded." ); 90 91 return true; 91 92 } … … 96 97 if ( !result ) 97 98 { 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!" ); 99 101 } 100 102 return result; … … 115 117 if ( ! NV_LIB_CLOSE( m_handle ) ) 116 118 { 117 NV_LOG_ERROR( "library : can't close library '", m_name, "'!" );119 NV_LOG_ERROR( "library \"", string_view( m_name ), "\" : can't close library!" ); 118 120 } 119 121 m_handle = nullptr; -
trunk/src/gfx/texture_font.cc
r399 r403 11 11 12 12 using namespace nv; 13 14 #define NV_CHECK_FREETYPE_ERROR( error, ... ) \ 15 if ( error != 0 ) { \ 16 NV_LOG_CRITICAL( "freetype : ", __VA_ARGS__ ); \ 17 NV_ABORT( "freetype : freetype library error!" ); \ 18 } 13 19 14 20 texture_glyph::texture_glyph() … … 45 51 46 52 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 ); 48 54 49 55 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 ); 51 57 52 58 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 ); 54 60 55 61 FT_Set_Transform( (FT_Face)(m_rface), &matrix, NULL ); … … 123 129 FT_UInt glyph_index = FT_Get_Char_Index( face, c ); 124 130 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 ); 130 132 131 133 FT_GlyphSlot slot = face->glyph; … … 141 143 if ( r.pos.x < 0 ) 142 144 { 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!" ); 145 147 } 146 148 if (depth == 4) -
trunk/src/gl/gl_context.cc
r398 r403 379 379 void gl_context::set_viewport( const ivec4& viewport ) 380 380 { 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!" ); 386 382 m_viewport = viewport; 387 383 glViewport( viewport.x, viewport.y, viewport.z, viewport.w ); … … 456 452 } 457 453 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 }462 454 463 455 if ( scissor.enabled ) 464 456 { 457 NV_ASSERT_ALWAYS( scissor.dim.x > 0 && scissor.dim.y > 0, "scissor_test.rect dimension equal to zero!" ); 458 465 459 if ( m_render_state.scissor_test.dim != scissor.dim || m_render_state.scissor_test.pos != scissor.pos ) 466 460 { … … 514 508 void gl_context::apply_depth_range( const depth_range& range ) 515 509 { 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!" ); 524 512 525 513 if ((m_render_state.depth_range.far != range.far) || -
trunk/src/gl/gl_device.cc
r399 r403 238 238 if ( fatal ) 239 239 { 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!" ); 242 242 } 243 243 } … … 257 257 if ( fatal ) 258 258 { 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!" ); 261 261 } 262 262 } -
trunk/src/lua/lua_state.cc
r399 r403 15 15 16 16 // 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 17 22 18 23 lua::stack_guard::stack_guard( lua::state* aL ) … … 424 429 if ( lua_isnil( m_state, -1 ) ) 425 430 { 426 NV_ THROW( runtime_error, lua_name.to_string() +" type not registered!" );431 NV_LUA_ABORT( "state::register_object", lua_name, " type not registered!" ); 427 432 } 428 433 deep_pointer_copy( -1, o ); … … 436 441 if ( lua_isnil( m_state, -1 ) ) 437 442 { 438 NV_ THROW( runtime_error, storage.to_string() +" storage not registered!" );443 NV_LUA_ABORT( "state::register_proto", "\"", storage, "\" storage not registered!" ); 439 444 } 440 445 lua_getfield( m_state, -1, id.data() ); 441 446 if ( lua_isnil( m_state, -1 ) ) 442 447 { 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, "\"!" ); 444 449 } 445 450 return lua::ref( luaL_ref( m_state, LUA_REGISTRYINDEX ) ); … … 452 457 if ( lua_isnil( m_state, -1 ) ) 453 458 { 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!" ); 455 460 } 456 461 lua_pushcfunction( m_state, f ); … … 502 507 if ( has_functions || has_metatable ) 503 508 { 504 lua_push string( m_state, "__ptr" );509 lua_pushliteral( m_state, "__ptr" ); 505 510 lua_pushlightuserdata( m_state, obj ); 506 511 lua_rawset( m_state, -3 ); … … 569 574 if ( lua_isnil( m_state, -1 ) ) 570 575 { 571 NV_ THROW( runtime_error, name.to_string() +" type not registered!" );576 NV_LUA_ABORT( "state::register_singleton", "\"", name, "\" type not registered!" ); 572 577 } 573 578 deep_pointer_copy( -1, o ); -
trunk/src/stl/assert.cc
r402 r403 9 9 #include "nv/base/assert.hh" 10 10 #undef NV_BASE_COMMON_HH 11 #include "nv/core/logging.hh" 11 12 13 extern "C" { 12 14 #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 } 13 20 14 # 15 21 #if NV_DEBUG 22 # if NV_COMPILER == NV_MSVC 16 23 extern "C" { 17 24 void __cdecl _wassert( const wchar_t * _Message, const wchar_t *_File, unsigned _Line ); 18 25 } 19 26 20 void nv _internal_assert( const wchar_t * message, const wchar_t* file, unsigned line )27 void nv::detail::assert_fail( const wchar_t * message, const wchar_t* file, unsigned line ) 21 28 { 22 29 _wassert( message, file, line ); 23 30 } 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 30 32 # if NV_COMPILER == NV_CLANG 31 33 extern "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; 34 35 } 36 #define NV_ASSERT_IMPL __assert 35 37 # else 36 38 extern "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; 39 40 } 41 #define NV_ASSERT_IMPL __assert_fail 40 42 # endif 41 __attribute__( ( __noreturn__ ) ) void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function )43 NV_NORETURN void nv::detail::assert_fail( const char * assertion, const char * file, unsigned int line, const char * function ) 42 44 { 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 ); 52 46 } 53 47 # endif 54 48 55 #endif // NV_ COMPILER49 #endif // NV_DEBUG 56 50 51 NV_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 59 NV_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.