From c3f29220eac1d1ed90f1262a55cd65c41d7a3b1e Mon Sep 17 00:00:00 2001 From: aura Date: Sat, 14 Mar 2026 01:12:57 +0100 Subject: fix textures in 2d render, some bugfix --- src/util/string.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 04bd9c6..2268a36 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -137,7 +137,7 @@ struct __str : public LIST { } U8 equals( const CT* rhs ) { - for( U32 i = 0; i < this->size; ++i ) { + for( U32 i = 0; i < this->size + 1; ++i ) { if( !rhs[i] || this->data[i] != rhs[i] ) return 0; } @@ -158,13 +158,15 @@ struct __str : public LIST { this->data[c] = 0; this->size = c; va_end( args2 ); + + return *this; } __str& append( const CT* str ) { U32 len; for( len = 0; !!str[len]; ++len ); if( this->size + len > this->capacity ) - this->reserve( this->size * 2 ); + this->reserve( this->size + len + 1 ); memcpy( this->data + this->size, str, len * sizeof(CT) ); this->size += len; @@ -173,7 +175,7 @@ struct __str : public LIST { } __str& append( const __str& str ) { - U32 len = str.len; + U32 len = str.size; if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); @@ -212,6 +214,8 @@ struct __str : public LIST { if( found ) return i; } + + return -1; } CT* find( const CT* str ) { -- cgit v1.2.3 From e2829336cfedb39d23263f75b61ed969c8193534 Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 16 Mar 2026 03:34:03 +0100 Subject: fix leak --- src/util/string.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 2268a36..6d44b53 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -54,15 +54,15 @@ struct ARRSTR { template struct __str : public LIST { __str() : LIST() {} - __str( U32 count, const CT* str ) : LIST() { + __str( U32 count, const CT* str ) { this->data = 0; - this->capacity = 0; + this->capacity = this->size = 0; this->reserve( count * 2 ); memcpy( this->data, str, count ); this->size = count; this->data[this->size] = 0; } - __str( const CT* fmt, ... ) : LIST() { + __str( const CT* fmt, ... ) { va_list args; va_start( args, fmt ); va_list args2; @@ -70,7 +70,7 @@ struct __str : public LIST { U32 c = vsnprintf( 0, 0, fmt, args ); va_end( args ); this->data = 0; - this->capacity = 0; + this->capacity = this->size = 0; this->reserve( c * 2 ); vsnprintf( this->data, c + 1, fmt, args2 ); this->data[c] = 0; @@ -165,7 +165,7 @@ struct __str : public LIST { __str& append( const CT* str ) { U32 len; for( len = 0; !!str[len]; ++len ); - if( this->size + len > this->capacity ) + if( this->size + len + 1 > this->capacity ) this->reserve( this->size + len + 1 ); memcpy( this->data + this->size, str, len * sizeof(CT) ); -- cgit v1.2.3 From fdc5e8760fb7ac0af8e7ebb98a2076db15e31082 Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 16 Mar 2026 10:15:01 +0100 Subject: giga refactor, fix ALL the leaks --- src/util/string.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 6d44b53..7dfab69 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -54,23 +54,19 @@ struct ARRSTR { template struct __str : public LIST { __str() : LIST() {} - __str( U32 count, const CT* str ) { - this->data = 0; - this->capacity = this->size = 0; + __str( U32 count, const CT* str ) : LIST() { this->reserve( count * 2 ); memcpy( this->data, str, count ); this->size = count; this->data[this->size] = 0; } - __str( const CT* fmt, ... ) { + __str( const CT* fmt, ... ) : LIST() { va_list args; va_start( args, fmt ); va_list args2; va_copy( args2, args ); U32 c = vsnprintf( 0, 0, fmt, args ); va_end( args ); - this->data = 0; - this->capacity = this->size = 0; this->reserve( c * 2 ); vsnprintf( this->data, c + 1, fmt, args2 ); this->data[c] = 0; @@ -89,8 +85,6 @@ struct __str : public LIST { if( this->data && this->data != other.data ) free( this->data ); - this->data = 0; - if( !other.capacity || !other.size ) { this->capacity = 1; this->size = 0; @@ -116,8 +110,9 @@ struct __str : public LIST { __str operator+( const CT rhs ) { __str ret = *this; ret.push( rhs ); return ret; } __str& operator+=( const __str& rhs ) { return this->append( rhs ); } __str& operator+=( const CT* rhs ) { return this->append( rhs ); } - __str& operator+=( const CT rhs ) { this->push( rhs ); return this; } + __str& operator+=( const CT rhs ) { this->push( rhs ); return *this; } + operator const CT*() { return this->data; } operator CT*() { return this->data; } CT operator[]( U32 i ) { @@ -128,10 +123,8 @@ struct __str : public LIST { if( rhs.size != this->size ) return 0; - for( U32 i = 0; i < this->size; ++i ) { - if( this->data[i] != rhs.data[i] ) - return 0; - } + if( !!memcmp( this->data, rhs.data, this->size ) ) + return 0; return 1; } @@ -165,7 +158,7 @@ struct __str : public LIST { __str& append( const CT* str ) { U32 len; for( len = 0; !!str[len]; ++len ); - if( this->size + len + 1 > this->capacity ) + if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); memcpy( this->data + this->size, str, len * sizeof(CT) ); @@ -179,7 +172,7 @@ struct __str : public LIST { if( this->size + len + 1 >= this->capacity ) this->reserve( this->size + len + 1 ); - memcpy( this->data + this->size, str, len * sizeof(CT) ); + memcpy( this->data + this->size, str.data, len * sizeof(CT) ); this->size += len; this->data[this->size] = 0; return *this; -- cgit v1.2.3 From 991352b0d2767e6bd1a46f554db4ac9d208c13ad Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 16 Mar 2026 15:40:03 +0100 Subject: finish prop rewrite --- src/util/string.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 7dfab69..672fb5d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -274,3 +274,11 @@ struct __str : public LIST { using STR = __str; using WSTR = __str; + +inline STR to_str( F32 f ) { return STR( "%.02f", f ); } +inline STR to_str( F64 f ) { return STR( "%.02g", f ); } +inline STR to_str( I32 i ) { return STR( "%d", i ); } +inline STR to_str( I64 i ) { return STR( "%lld", i ); } +inline STR to_str( U32 u ) { return STR( "%u", u ); } +inline STR to_str( U64 u ) { return STR( "%llu", u ); } +inline STR to_str( void* p ) { return STR( "%llx", (U64)p ); } -- cgit v1.2.3