Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Two questions: CFileDialog & vector

Two questions: CFileDialog & vector

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncementgraphicsdebuggingquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dean Goodman
    wrote on last edited by
    #1

    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

    C J 2 Replies Last reply
    0
    • D Dean Goodman

      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

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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!

      ISEffects - effects for images

      D 1 Reply Last reply
      0
      • C Chris Losinger

        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!

        ISEffects - effects for images

        D Offline
        D Offline
        Dean Goodman
        wrote on last edited by
        #3

        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 here

        It'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

        1 Reply Last reply
        0
        • D Dean Goodman

          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

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups