mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-03 18:45:28 +00:00
Allocate 2 instead of 1 byte per char for buffer used in WinGLNative.HandleDropFiles
DragQueryFile returns number of characters. Previously, a buffer of 'number of characters' bytes was being allocated. This change fixes crashing when the platform uses a character set with more than one byte per character. (unicode charset has 2 bytes) Fixes #626
This commit is contained in:
parent
254f7e9bfb
commit
a3c0b05371
|
@ -692,10 +692,11 @@ namespace OpenTK.Platform.Windows
|
||||||
for (uint i = 0; i < filesCounter; ++i)
|
for (uint i = 0; i < filesCounter; ++i)
|
||||||
{
|
{
|
||||||
// Don't forget about \0 at the end
|
// Don't forget about \0 at the end
|
||||||
uint fileNameSize = Functions.DragQueryFile(hDrop, i, IntPtr.Zero, 0) + 1;
|
uint filenameChars = Functions.DragQueryFile(hDrop, i, IntPtr.Zero, 0) + 1;
|
||||||
IntPtr str = Marshal.AllocHGlobal((int)fileNameSize);
|
int filenameSize = (int)(filenameChars * 2); // for unicode char set, 2 bytes per character
|
||||||
|
IntPtr str = Marshal.AllocHGlobal(filenameSize);
|
||||||
|
|
||||||
Functions.DragQueryFile(hDrop, i, str, fileNameSize);
|
Functions.DragQueryFile(hDrop, i, str, filenameChars);
|
||||||
|
|
||||||
string dropString = Marshal.PtrToStringAuto(str);
|
string dropString = Marshal.PtrToStringAuto(str);
|
||||||
OnFileDrop(dropString);
|
OnFileDrop(dropString);
|
||||||
|
|
Loading…
Reference in a new issue