-
-
Notifications
You must be signed in to change notification settings - Fork 439
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
As I was debugging a different problem, I noticed that SilkMarshal.PtrToStringArray ignores the encoding parameter.
This leads to incorrect behavior when not using the default encoding.
This incorrect behavior can be seen when converting to a pointer and back.
Silk.NET/src/Core/Silk.NET.Core/Native/SilkMarshal.cs
Lines 428 to 439 in 8da3988
| public static unsafe void CopyPtrToStringArray | |
| ( | |
| nint ptr, | |
| string[] arr, | |
| NativeStringEncoding encoding = NativeStringEncoding.Ansi | |
| ) | |
| { | |
| for (var i = 0; i < arr.Length; i++) | |
| { | |
| arr[i] = PtrToString(((nint*) ptr)![i]); | |
| } | |
| } |
Steps to reproduce
Run https://dotnetfiddle.net/zQNrbf with Silk.NET.Core v2.22.0 added.
This will be the output:
Note how some strings are truncated.
----- String array -----
BStr
H
F
B
1
LPStr
Hello world
Foo
Bar
123
LPTStr
Hello world
Foo
Bar
123
LPUTF8Str
Hello world
Foo
Bar
123
LPWStr
H
F
B
1
Comments
This issue seems to be easy to fix so I can submit a pull request if wanted.
The single string variants (StringToPtr and PtrToString) work fine. The issue is only found in PtrToStringArray.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done