Working on my plugin running on Rhinoceros (x64) and developed using vc++ on visaul studio 2010 I founded a strange issue.
I need to convert an ON_wString to a std::wstring but it throws an exception.
An example of the code follows:
std::wstring stdString1 = L""; wchar_t charArray1; memset(charArray1, L'\0', 256); charArray1 = 'a'; ON_wString onString1(charArray1); stdString1 = onString1.Array(); // It works std::wstring stdString = L""; wchar_t charArray; memset(charArray, L'\0', 256); ON_wString onString(charArray); stdString = onString.Array(); // Unhandled exception: Access violation reading // location 0x0000000000000000
It seems that a call to the function ON_wString::Array() retruns a NULL pointer if the string is empty.
I expected it returns a valid pointer to an empty char (like std::wstring does).
Is it a bug, a desired behavior or I’m doing something wrong?
During the copy of an ON_wString to a std::wstring (e.g.
std::wstring stdString = ON_wString(“foo”)) which is the function that handles the conversion?
I though there was a cast operator from ON_wString to wchar_t* or something similar but I did not find such a function.