Two questions: CFileDialog & vector
-
CFileDialog dlg(TRUE, NULL, lastPath, OFN_ALLOWMULTISELECT, _T("Text file (.txt)|*.txt|") _T("All files (*.*) |*.*|") ); ... if (dlg.DoModal() != IDOK) DoSomething(); ... The above code works fine in the debug version, but curiosly enough, the dialog box hangs in the release version when a file is selected and the 'Open' button is pressed. Any ideas? ------------------------ Secondly, I have a set up like the following: CClass1 { ... vector data; ... } CClass2 { //member funcs private: std::string str; int x; ... (member variables) } CClass1* obj; ... delete obj; //crash here In my code I have a pointer to a CClass1 object (which I know is valid) that I am trying to deallocate. The program crashes when I call delete. After much time spent, I know the problem arises when the last object in the data vector is deleted. I've tried using the default destructor to take care of deallocating the vector, I've tried calling data.resize(0);, data.clear();, and while (data.size()) data.pop_back(); -- all with the same result. Deleting the last object in the vector causes an assertion in dbgheap.c Expression:_CrtIsValidHeapPointer(pUserData) More specifically, the assertion always occurs when the str member of CClass2 is being deallocated. Note that this is not a pointer to a string being deleted - it is a string object. Thus there should not be an issue with deleting the same string twice. I thought maybe I had done something stupid and corrupted the heap along the way, but I've been looking over my code for a long time now and I'm fairly certain there are no double deletes, dangling pointers, etc. I know the above might not be very clear, but any insight would be appreciated. Thanks, DG
-
CFileDialog dlg(TRUE, NULL, lastPath, OFN_ALLOWMULTISELECT, _T("Text file (.txt)|*.txt|") _T("All files (*.*) |*.*|") ); ... if (dlg.DoModal() != IDOK) DoSomething(); ... The above code works fine in the debug version, but curiosly enough, the dialog box hangs in the release version when a file is selected and the 'Open' button is pressed. Any ideas? ------------------------ Secondly, I have a set up like the following: CClass1 { ... vector data; ... } CClass2 { //member funcs private: std::string str; int x; ... (member variables) } CClass1* obj; ... delete obj; //crash here In my code I have a pointer to a CClass1 object (which I know is valid) that I am trying to deallocate. The program crashes when I call delete. After much time spent, I know the problem arises when the last object in the data vector is deleted. I've tried using the default destructor to take care of deallocating the vector, I've tried calling data.resize(0);, data.clear();, and while (data.size()) data.pop_back(); -- all with the same result. Deleting the last object in the vector causes an assertion in dbgheap.c Expression:_CrtIsValidHeapPointer(pUserData) More specifically, the assertion always occurs when the str member of CClass2 is being deallocated. Note that this is not a pointer to a string being deleted - it is a string object. Thus there should not be an issue with deleting the same string twice. I thought maybe I had done something stupid and corrupted the heap along the way, but I've been looking over my code for a long time now and I'm fairly certain there are no double deletes, dangling pointers, etc. I know the above might not be very clear, but any insight would be appreciated. Thanks, DG
1. with multi-select, you have to provide a buffer big enough to store all the filenames. 2. hard to tell. try reposting with your code in PRE, /PRE brackets, or turn off the HTML stuff - looks like you lost some formatting. -c
Cheap oil. It's worth it!
-
1. with multi-select, you have to provide a buffer big enough to store all the filenames. 2. hard to tell. try reposting with your code in PRE, /PRE brackets, or turn off the HTML stuff - looks like you lost some formatting. -c
Cheap oil. It's worth it!
Tried the change you suggested for multi-select -- I removed it completely. The result is still the same. The dialog box still hangs with only one file selected. As for the other code:
CClass1 {
...
vector data;
...
}CClass2 {
//member funcs
private:
std::string str;
int x;
... (member variables)
}CClass1* obj;
...
delete obj; //crash hereIt's just code stubs, but hopefully that will look better for you. The main issue is just that it always fails when the str member is being deallocated. When unwinding the stack the last calls before the crash are: 1. The string destructor 2. basic_string::_Tidy() 3. std::allocator::deallocate 4. operator delete (void*) (note that those are cleaned up names since everything is templatized...) --DG
-
CFileDialog dlg(TRUE, NULL, lastPath, OFN_ALLOWMULTISELECT, _T("Text file (.txt)|*.txt|") _T("All files (*.*) |*.*|") ); ... if (dlg.DoModal() != IDOK) DoSomething(); ... The above code works fine in the debug version, but curiosly enough, the dialog box hangs in the release version when a file is selected and the 'Open' button is pressed. Any ideas? ------------------------ Secondly, I have a set up like the following: CClass1 { ... vector data; ... } CClass2 { //member funcs private: std::string str; int x; ... (member variables) } CClass1* obj; ... delete obj; //crash here In my code I have a pointer to a CClass1 object (which I know is valid) that I am trying to deallocate. The program crashes when I call delete. After much time spent, I know the problem arises when the last object in the data vector is deleted. I've tried using the default destructor to take care of deallocating the vector, I've tried calling data.resize(0);, data.clear();, and while (data.size()) data.pop_back(); -- all with the same result. Deleting the last object in the vector causes an assertion in dbgheap.c Expression:_CrtIsValidHeapPointer(pUserData) More specifically, the assertion always occurs when the str member of CClass2 is being deallocated. Note that this is not a pointer to a string being deleted - it is a string object. Thus there should not be an issue with deleting the same string twice. I thought maybe I had done something stupid and corrupted the heap along the way, but I've been looking over my code for a long time now and I'm fairly certain there are no double deletes, dangling pointers, etc. I know the above might not be very clear, but any insight would be appreciated. Thanks, DG
As for the first question, the strings must end with "||". As for the second question, could you please repost checking the option "Display this message as-is (no HTML)" right below the edit area? That will bring the missing portions of the code into the light. Thank you. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo