11using System ;
22using System . Numerics ;
3+ using System . Runtime . CompilerServices ;
34using System . Text ;
45
56namespace ImGuiNET
@@ -88,22 +89,25 @@ public static bool InputText(
8889 Encoding . UTF8 . GetBytes ( labelPtr , label . Length , labelBytes , labelByteCount ) ;
8990 }
9091
91- int bytesNeeded = Encoding . UTF8 . GetByteCount ( input ) ;
92- int stackBufSize = Math . Max ( ( int ) maxLength , bytesNeeded ) ;
92+ int originalByteCount = Encoding . UTF8 . GetByteCount ( input ) ;
93+ int stackBufSize = Math . Max ( ( int ) maxLength , originalByteCount ) ;
9394 byte * bufBytes = stackalloc byte [ stackBufSize ] ;
9495 fixed ( char * u16Ptr = input )
9596 {
9697 Encoding . UTF8 . GetBytes ( u16Ptr , input . Length , bufBytes , stackBufSize ) ;
9798 }
9899
100+ byte * originalBufBytes = stackalloc byte [ originalByteCount ] ;
101+ Unsafe . CopyBlock ( originalBufBytes , bufBytes , ( uint ) originalByteCount ) ;
102+
99103 byte result = ImGuiNative . igInputText (
100104 labelBytes ,
101105 bufBytes ,
102106 ( uint ) stackBufSize ,
103107 flags ,
104108 callback ,
105109 user_data . ToPointer ( ) ) ;
106- if ( ! Util . AreStringsEqual ( input , bufBytes ) )
110+ if ( ! Util . AreStringsEqual ( originalBufBytes , originalByteCount , bufBytes ) )
107111 {
108112 input = Util . StringFromPtr ( bufBytes ) ;
109113 }
@@ -148,14 +152,17 @@ public static bool InputTextMultiline(
148152 Encoding . UTF8 . GetBytes ( labelPtr , label . Length , labelBytes , labelByteCount ) ;
149153 }
150154
151- int bytesNeeded = Encoding . UTF8 . GetByteCount ( input ) ;
152- int stackBufSize = Math . Max ( ( int ) maxLength , bytesNeeded ) ;
155+ int originalByteCount = Encoding . UTF8 . GetByteCount ( input ) ;
156+ int stackBufSize = Math . Max ( ( int ) maxLength , originalByteCount ) ;
153157 byte * bufBytes = stackalloc byte [ stackBufSize ] ;
154158 fixed ( char * u16Ptr = input )
155159 {
156160 Encoding . UTF8 . GetBytes ( u16Ptr , input . Length , bufBytes , stackBufSize ) ;
157161 }
158162
163+ byte * originalBufBytes = stackalloc byte [ originalByteCount ] ;
164+ Unsafe . CopyBlock ( originalBufBytes , bufBytes , ( uint ) originalByteCount ) ;
165+
159166 byte result = ImGuiNative . igInputTextMultiline (
160167 labelBytes ,
161168 bufBytes ,
@@ -164,7 +171,7 @@ public static bool InputTextMultiline(
164171 flags ,
165172 callback ,
166173 user_data . ToPointer ( ) ) ;
167- if ( ! Util . AreStringsEqual ( input , bufBytes ) )
174+ if ( ! Util . AreStringsEqual ( originalBufBytes , originalByteCount , bufBytes ) )
168175 {
169176 input = Util . StringFromPtr ( bufBytes ) ;
170177 }
0 commit comments