I have a structure defined in my header file:
struct video
{
wchar_t* videoName;
std::vector<wchar_t*> audio;
std::vector<wchar_t*> subs;
};
struct ret
{
std::vector<video*> videos;
wchar_t* errMessage;
};
struct params{
HWND form;
wchar_t* cwd;
wchar_t* disk;
ret* returnData;
};
When I try to add my video structure to a vector of video* I get access violation reading 0xcdcdcdc1 (videoName is @ 0xcdcdcdcd, before I allocate it)
//extract of code where problem is
video v;
v.videoName = (wchar_t*)malloc((wcslen(line)+1)*sizeof(wchar_t));
wcscpy(v.videoName,line);
p->returnData->videos.push_back(&v); //error here
I would guess that either
porp->returnDatais an uninitialized/invalid pointer.Also, this isn’t causing your crash, but it will once you fix the current problem: beware of returning the pointer to a local variable. Once your function goes out of scope the local vector will be destroyed and
&vwill be an invalid pointer. If you want your vector to exist beyond the scope of the current function then you will need to allocate it on the heap: