I think the problem is in the addBytesToPointer loop over the files. But its possible the error is actually with the number of bytes returned by
String::copyToUTF16. The docs say returns the number of bytes copied to the buffer, including the terminating null character. But when adding the filenames together there is no terminating NULL.
Anyway, i’m sure you’ll figure it out! (I’m on the June 30 GIT, but I did a quick check of the commit logs to see if there was anything added)
[code]
static HDROP createHDrop (const StringArray& fileNames)
{
int totalBytes = 0;
for (int i = fileNames.size(); --i >= 0;)
totalBytes += CharPointer_UTF16::getBytesRequiredFor (fileNames[i].getCharPointer()) + sizeof (WCHAR);
I don’t understand… I think my code is absolutely fine. It looks like your change will just leave two null characters after every filename, which would mean that only the first one will be used. My code leaves a single null after each filename, and then two at the end, which is what it’s supposed to do. (Or am I totally misunderstanding?)
for (int i = 0; i < fileNames.size(); ++i)
{
DBG(fileNames[i].length());
const int bytesWritten = fileNames[i].copyToUTF16 (fname, 2048);
fname = reinterpret_cast<WCHAR*> (addBytesToPointer (fname, bytesWritten+sizeof(WCHAR)));
}
I get the filenames length == 49, but the bytesWritten returns back with 98, I would expect bytes written to be 100? (49 characters long + a NULL char == 50 *sizeof(WCHAR) == 100)
So maybe my initial suspicion with copyToUTF16 was right?
Here’s a little test case
String utfTest("atest");
DBG(utfTest.length());
HeapBlock<CharPointer_UTF16::CharType> charBuffer(2048);
int bytesWritten=utfTest.copyToUTF16(charBuffer, 2048/sizeof(CharPointer_UTF16::CharType));
DBG(bytesWritten);
Outputs on my version(I do need to checkout the most recent version from GIT though, so go ahead and yell ‘I fixed it’ if you have!)
Ah, yes, you’re right, copyToUTF16 doesn’t seem to be returning the correct value. The problem is actually in CharacterFunctions::copyWithDestByteLimit(), which should return this:
Hi Jules,
I assume the copyToUTF16 fix is in the tip, but what do you think about moving this fix also into the juce_153 branch? Bugs like this always seem to pop-up once in a while, one more serious than others. Because you are always working on newer code in the trunk it’s not always safe for us to update to the tip, i’ve done this a couple of times and a few times it fixed a current bug but introduced new ones.
Wouldn’t be a good thing to have a stable branch (1_53) which doesn’t get updated with new features but do get the bug fixes? I know it’s more work but would make more sense. Your codebase is getting so big and with additions like ios and android support it’s much harder to maintain a bug free main branch.
I’ve not put it into the tip yet, because I’m in the middle of the “Jucequake” re-organisation at the moment. When that’s done I’ll probably do a new release soon afterwards, and then might indeed think about stable branches, etc., which will be more straightforward when everything is more modularised.