Note that there are some explanatory texts on larger screens.

plurals
  1. POAllocating a std::string with std::vector iterators causes debug errors in one project, but works in another?
    text
    copied!<p>I am trying to get the name of an input device, using the RawInput API, but I get a weird error when I allocate the name string.Basically I saw this in another project where it worked perfectly.This is the flawed code:</p> <pre><code>std::string Input::GetDeviceName(void* device) { size_t size; bool result = GetRawInputDeviceInfo(device, RIDI_DEVICENAME, null, &amp;size) ; if(result &lt; 0) { throw RawInputException(GetLastError(), L"GetRawInputDeviceInfo(InputDeviceDataRequest::Name)"); } std::vector&lt;std::string::value_type&gt; data(size); result = GetRawInputDeviceInfo(device, RIDI_DEVICENAME, &amp;data[0], &amp;size); if(result &lt; 0) { throw RawInputException(GetLastError(), L"GetRawInputDeviceInfo(InputDeviceDataRequest::Name)"); } std::string name = std::string(data.cbegin(), data.cend()); return(name); } </code></pre> <p>The same code worked fine in the tutorial implementation i read it from, however when I use it it triggers a breakpoint at <strong>*HeapAlloc(_crtheap, 0, size ? size : 1);*</strong>, somewhere 10 levels down the call stack from <strong>std::string _name = std::string(data.cbegin(), data.cend());</strong>.I checked the value of the vector, it has a size of 61.I think the problem is with the actual contents?But what could go wrong with std::string::value_type?GetRawInputDeviceInfo() returns true, so it successfully filled up the vector with chars.And as I mentioned, the tutorial code where I read it from built and ran perfectly.For those interested, here's a link to the project: <a href="https://code.google.com/p/rawinput/" rel="nofollow">The guy stopped updating it, but its almost fully functional</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload