@@ -48,41 +48,59 @@ public unsafe partial struct ImFontAtlasPtr
4848 public RangeAccessor < int > CustomRectIds => new RangeAccessor < int > ( NativePtr ->CustomRectIds , 1 ) ;
4949 public ImFontPtr AddFontFromMemoryCompressedBase85TTF ( string compressed_font_data_base85 , float size_pixels )
5050 {
51- int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
52- byte * native_compressed_font_data_base85 = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
53- fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
51+ byte * native_compressed_font_data_base85 ;
52+ if ( compressed_font_data_base85 != null )
5453 {
55- int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
56- native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
54+ int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
55+ byte * native_compressed_font_data_base85_stackBytes = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
56+ native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes ;
57+ fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
58+ {
59+ int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
60+ native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
61+ }
5762 }
63+ else { native_compressed_font_data_base85 = null ; }
5864 ImFontConfig * font_cfg = null ;
5965 ushort * glyph_ranges = null ;
6066 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromMemoryCompressedBase85TTF ( NativePtr , native_compressed_font_data_base85 , size_pixels , font_cfg , glyph_ranges ) ;
6167 return new ImFontPtr ( ret ) ;
6268 }
6369 public ImFontPtr AddFontFromMemoryCompressedBase85TTF ( string compressed_font_data_base85 , float size_pixels , ImFontConfigPtr font_cfg )
6470 {
65- int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
66- byte * native_compressed_font_data_base85 = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
67- fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
71+ byte * native_compressed_font_data_base85 ;
72+ if ( compressed_font_data_base85 != null )
6873 {
69- int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
70- native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
74+ int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
75+ byte * native_compressed_font_data_base85_stackBytes = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
76+ native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes ;
77+ fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
78+ {
79+ int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
80+ native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
81+ }
7182 }
83+ else { native_compressed_font_data_base85 = null ; }
7284 ImFontConfig * native_font_cfg = font_cfg . NativePtr ;
7385 ushort * glyph_ranges = null ;
7486 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromMemoryCompressedBase85TTF ( NativePtr , native_compressed_font_data_base85 , size_pixels , native_font_cfg , glyph_ranges ) ;
7587 return new ImFontPtr ( ret ) ;
7688 }
7789 public ImFontPtr AddFontFromMemoryCompressedBase85TTF ( string compressed_font_data_base85 , float size_pixels , ImFontConfigPtr font_cfg , IntPtr glyph_ranges )
7890 {
79- int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
80- byte * native_compressed_font_data_base85 = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
81- fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
91+ byte * native_compressed_font_data_base85 ;
92+ if ( compressed_font_data_base85 != null )
8293 {
83- int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
84- native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
94+ int compressed_font_data_base85_byteCount = Encoding . UTF8 . GetByteCount ( compressed_font_data_base85 ) ;
95+ byte * native_compressed_font_data_base85_stackBytes = stackalloc byte [ compressed_font_data_base85_byteCount + 1 ] ;
96+ native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes ;
97+ fixed ( char * compressed_font_data_base85_ptr = compressed_font_data_base85 )
98+ {
99+ int native_compressed_font_data_base85_offset = Encoding . UTF8 . GetBytes ( compressed_font_data_base85_ptr , compressed_font_data_base85 . Length , native_compressed_font_data_base85 , compressed_font_data_base85_byteCount ) ;
100+ native_compressed_font_data_base85 [ native_compressed_font_data_base85_offset ] = 0 ;
101+ }
85102 }
103+ else { native_compressed_font_data_base85 = null ; }
86104 ImFontConfig * native_font_cfg = font_cfg . NativePtr ;
87105 ushort * native_glyph_ranges = ( ushort * ) glyph_ranges . ToPointer ( ) ;
88106 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromMemoryCompressedBase85TTF ( NativePtr , native_compressed_font_data_base85 , size_pixels , native_font_cfg , native_glyph_ranges ) ;
@@ -218,41 +236,59 @@ public ImFontPtr AddFontFromMemoryTTF(IntPtr font_data, int font_size, float siz
218236 }
219237 public ImFontPtr AddFontFromFileTTF ( string filename , float size_pixels )
220238 {
221- int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
222- byte * native_filename = stackalloc byte [ filename_byteCount + 1 ] ;
223- fixed ( char * filename_ptr = filename )
239+ byte * native_filename ;
240+ if ( filename != null )
224241 {
225- int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
226- native_filename [ native_filename_offset ] = 0 ;
242+ int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
243+ byte * native_filename_stackBytes = stackalloc byte [ filename_byteCount + 1 ] ;
244+ native_filename = native_filename_stackBytes ;
245+ fixed ( char * filename_ptr = filename )
246+ {
247+ int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
248+ native_filename [ native_filename_offset ] = 0 ;
249+ }
227250 }
251+ else { native_filename = null ; }
228252 ImFontConfig * font_cfg = null ;
229253 ushort * glyph_ranges = null ;
230254 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromFileTTF ( NativePtr , native_filename , size_pixels , font_cfg , glyph_ranges ) ;
231255 return new ImFontPtr ( ret ) ;
232256 }
233257 public ImFontPtr AddFontFromFileTTF ( string filename , float size_pixels , ImFontConfigPtr font_cfg )
234258 {
235- int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
236- byte * native_filename = stackalloc byte [ filename_byteCount + 1 ] ;
237- fixed ( char * filename_ptr = filename )
259+ byte * native_filename ;
260+ if ( filename != null )
238261 {
239- int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
240- native_filename [ native_filename_offset ] = 0 ;
262+ int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
263+ byte * native_filename_stackBytes = stackalloc byte [ filename_byteCount + 1 ] ;
264+ native_filename = native_filename_stackBytes ;
265+ fixed ( char * filename_ptr = filename )
266+ {
267+ int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
268+ native_filename [ native_filename_offset ] = 0 ;
269+ }
241270 }
271+ else { native_filename = null ; }
242272 ImFontConfig * native_font_cfg = font_cfg . NativePtr ;
243273 ushort * glyph_ranges = null ;
244274 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromFileTTF ( NativePtr , native_filename , size_pixels , native_font_cfg , glyph_ranges ) ;
245275 return new ImFontPtr ( ret ) ;
246276 }
247277 public ImFontPtr AddFontFromFileTTF ( string filename , float size_pixels , ImFontConfigPtr font_cfg , IntPtr glyph_ranges )
248278 {
249- int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
250- byte * native_filename = stackalloc byte [ filename_byteCount + 1 ] ;
251- fixed ( char * filename_ptr = filename )
279+ byte * native_filename ;
280+ if ( filename != null )
252281 {
253- int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
254- native_filename [ native_filename_offset ] = 0 ;
282+ int filename_byteCount = Encoding . UTF8 . GetByteCount ( filename ) ;
283+ byte * native_filename_stackBytes = stackalloc byte [ filename_byteCount + 1 ] ;
284+ native_filename = native_filename_stackBytes ;
285+ fixed ( char * filename_ptr = filename )
286+ {
287+ int native_filename_offset = Encoding . UTF8 . GetBytes ( filename_ptr , filename . Length , native_filename , filename_byteCount ) ;
288+ native_filename [ native_filename_offset ] = 0 ;
289+ }
255290 }
291+ else { native_filename = null ; }
256292 ImFontConfig * native_font_cfg = font_cfg . NativePtr ;
257293 ushort * native_glyph_ranges = ( ushort * ) glyph_ranges . ToPointer ( ) ;
258294 ImFont * ret = ImGuiNative . ImFontAtlas_AddFontFromFileTTF ( NativePtr , native_filename , size_pixels , native_font_cfg , native_glyph_ranges ) ;
0 commit comments