diff --git a/renderdoc/replay/basic_types.cpp b/renderdoc/replay/basic_types.cpp index 038f678ce..bec8b181a 100644 --- a/renderdoc/replay/basic_types.cpp +++ b/renderdoc/replay/basic_types.cpp @@ -31,9 +31,16 @@ wstr &wstr::operator =(const std::wstring &in) { Delete(); count = (int32_t)in.size(); - elems = (wchar_t*)allocate(sizeof(wchar_t)*(count+1)); - memcpy(elems, &in[0], sizeof(wchar_t)*in.size()); - elems[count] = 0; + if(count == 0) + { + elems = L""; + } + else + { + elems = (wchar_t*)allocate(sizeof(wchar_t)*(count+1)); + memcpy(elems, &in[0], sizeof(wchar_t)*in.size()); + elems[count] = 0; + } return *this; } @@ -41,9 +48,16 @@ str &str::operator =(const std::string &in) { Delete(); count = (int32_t)in.size(); - elems = (char*)allocate(sizeof(char)*(count+1)); - memcpy(elems, &in[0], sizeof(char)*in.size()); - elems[count] = 0; + if(count == 0) + { + elems = ""; + } + else + { + elems = (char*)allocate(sizeof(char)*(count+1)); + memcpy(elems, &in[0], sizeof(char)*in.size()); + elems[count] = 0; + } return *this; } @@ -51,9 +65,16 @@ wstr &wstr::operator =(const wchar_t *const in) { Delete(); count = (int32_t)wcslen(in); - elems = (wchar_t*)allocate(sizeof(wchar_t)*(count+1)); - memcpy(elems, &in[0], sizeof(wchar_t)*count); - elems[count] = 0; + if(count == 0) + { + elems = L""; + } + else + { + elems = (wchar_t*)allocate(sizeof(wchar_t)*(count+1)); + memcpy(elems, &in[0], sizeof(wchar_t)*count); + elems[count] = 0; + } return *this; } @@ -61,9 +82,16 @@ str &str::operator =(const char *const in) { Delete(); count = (int32_t)strlen(in); - elems = (char*)allocate(sizeof(char)*(count+1)); - memcpy(elems, &in[0], sizeof(char)*count); - elems[count] = 0; + if(count == 0) + { + elems = ""; + } + else + { + elems = (char*)allocate(sizeof(char)*(count+1)); + memcpy(elems, &in[0], sizeof(char)*count); + elems[count] = 0; + } return *this; } diff --git a/renderdoc/replay/basic_types.h b/renderdoc/replay/basic_types.h index 4ea76c403..33272014b 100644 --- a/renderdoc/replay/basic_types.h +++ b/renderdoc/replay/basic_types.h @@ -71,9 +71,16 @@ struct array { Delete(); count = (int32_t)in.size(); - elems = (T*)allocate(sizeof(T)*count); - for(int32_t i=0; i < count; i++) - new (elems+i) T(in[i]); + if(count == 0) + { + elems = 0; + } + else + { + elems = (T*)allocate(sizeof(T)*count); + for(int32_t i=0; i < count; i++) + new (elems+i) T(in[i]); + } return *this; } @@ -117,7 +124,7 @@ struct str : public rdctype::array count = o.count; if(count == 0) { - elems = NULL; + elems = ""; } else { @@ -146,7 +153,7 @@ struct wstr : public rdctype::array count = o.count; if(count == 0) { - elems = 0; + elems = L""; } else { diff --git a/renderdoc/replay/type_helpers.h b/renderdoc/replay/type_helpers.h index 3842e8b0a..2235ca2ff 100644 --- a/renderdoc/replay/type_helpers.h +++ b/renderdoc/replay/type_helpers.h @@ -36,10 +36,17 @@ namespace rdctype template void create_array(array &ret, size_t count) { - ret.elems = (T*)ret.allocate(sizeof(T)*count); ret.count = (int32_t)count; - for(int32_t i=0; i < ret.count; i++) - new (ret.elems+i) T(); + if(ret.count == 0) + { + ret.elems = 0; + } + else + { + ret.elems = (T*)ret.allocate(sizeof(T)*count); + for(int32_t i=0; i < ret.count; i++) + new (ret.elems+i) T(); + } } #pragma warning(pop) @@ -47,9 +54,16 @@ void create_array(array &ret, size_t count) template void create_array_uninit(array &ret, size_t count) { - ret.elems = (T*)ret.allocate(sizeof(T)*count); ret.count = (int32_t)count; - memset(ret.elems, 0, sizeof(T)*count); + if(ret.count == 0) + { + ret.elems = 0; + } + else + { + ret.elems = (T*)ret.allocate(sizeof(T)*count); + memset(ret.elems, 0, sizeof(T)*count); + } } }; // namespace rdctype \ No newline at end of file