User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Crashing with MyVector.clear()

  1. #1
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Crashing with MyVector.clear()

    In my extension, I have tried to reset/empty a vector with MyVector.resize(0) and MyVector.clear(), but it always crashes the runtime! Wherever I use the resize() function it works fine, but if I do clear() or resize(0) it crashes!! Why is this?

    EDIT: Just FYI I already did google searching and nothing I found had any information on the problem or how to solve, all the results I found either hadn't been solved yet, or the person with the problem said they fixed it and didn't say how.
    Working as fast as I can on Fusion 3

  2. #2
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    Not nearly enough information.

    Presumably this is an STL vector? Give us some context - where are you using the vector, how are you using it, what are you storing in it (e.g. data or pointers?). If you're storing objects directly in the vector instead of pointers, that's a recipe for all sorts of unintended and subtle side-effects that can result in crashing your application.

    Likewise if you're holding an iterator to the vector, operations like resize will invalidate them.

  3. #3
    No Products Registered

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    Try debugging your extension to find out where the crash is. If you are using VC++ it will break on the line where the error occured.

    Otherwise, can you loop through the vector and delete each one manually with MyVector.erase()?

  4. #4
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    The line it crashes on is the line with MyVector.clear()

    As for more info, sorry about that I was frustrated.

    The vectors are defined in data.h and i use the rdPtr->MyVector to access them.

    The only thing I do to them is resize them with resize(new size, new data) and set values in them with MyVector[position] = data; (and I make sure this never goes out of range)

    The resizing happens in a function, and the value modifying happens directly in actions and in another function.
    Working as fast as I can on Fusion 3

  5. #5
    No Products Registered

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    If you are using STL, You shouldn't need to resize it, it will do it automatically.
    All you do is MyVector.push_back( data ) which will add a new entry to the back of the list.

  6. #6
    No Products Registered

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    1,141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    When you use objects in your rundata structure you need to store them as pointers and create them in the CreateObject function in runtime.cpp, rather than storing them directly in the struct. The reason for this is that MMF doesn't know the content of the rundata structure, only the size, and will only allocate the memory needed. No constructors will be called and any object stored in the struct will result in garbage data.

    The reason your example is crashing is most likely because the vector hasn't been properly created and therefore it's internal data is messed up, causing it to crash whenever you try to use it.

    Try storing the object as a pointer in your rundata structure, like:
    Code:
    Vector<int>* MyVector;
    Then, in CreateObject use:
    Code:
    rdPtr->MyVector = new Vector();
    And to avoid memory leaks you should also put the following in the DestroyObject function:
    Code:
    if(rdPtr->MyVector != null) delete rdPtr->MyVector;
    rdPtr->MyVector = null;
    Note that you will have to use the -> operator instead of . when you want to use the vector as the object now is a pointer, like:
    Code:
    rdPtr->MyVector->clear();
    You can also use the * operator to 'revert' one pointer depth, like
    Code:
    (*rdPtr->MyVector)[i] = 0;

  7. #7
    Clicker Fusion 2.5 DeveloperSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,739
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Crashing with MyVector.clear()

    Just for reference, it's vector, not Vector.

  8. #8
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    Werbad,I did exactly what you said and now I am getting all these errors:
    Code:
    1>.\Runtime.cpp(40) : error C2955: 'std::vector' : use of class template requires template argument list
    1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(438) : see declaration of 'std::vector'
    1>.\Runtime.cpp(40) : error C2512: 'std::vector' : no appropriate default constructor available
    1>.\Runtime.cpp(41) : error C2512: 'std::vector' : no appropriate default constructor available
    1>.\Runtime.cpp(61) : error C2065: 'null' : undeclared identifier
    1>.\Runtime.cpp(62) : error C2065: 'null' : undeclared identifier
    1>.\Runtime.cpp(64) : error C2065: 'null' : undeclared identifier
    1>.\Runtime.cpp(65) : error C2065: 'null' : undeclared identifier
    1>Main.cpp
    1>.\Main.cpp(83) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
    1>        with
    1>        [
    1>            _Ty=std::string
    1>        ]
    1>        C:\Program Files\Microsoft SDKs\Windows\v6.0A\\include\guiddef.h(192): could be 'int operator ==(const GUID &,const GUID &)'
    1>        while trying to match the argument list '(std::vector<_Ty>, std::string)'
    1>        with
    1>        [
    1>            _Ty=std::string
    1>        ]
    ...which leads to more errors in places that were just fine before. I think I misunderstood you somewhere?
    Working as fast as I can on Fusion 3

  9. #9
    Clicker Fusion 2.5 DeveloperSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,739
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Crashing with MyVector.clear()

    Just posting corrections (I gave them to him on Gwerdy):

    It's NULL, not null.
    As I already said, vector, not Vector.

    rdPtr->MyVector = new Vector();

    has to be

    rdPtr->MyVector = new vector<int>;

  10. #10
    Clickteam Clickteam
    LB's Avatar
    Join Date
    Jun 2007
    Location
    Richardson, Texas, North America
    Posts
    8,937
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Crashing with MyVector.clear()

    Thanks Looki. Also as you told me I can't use rdPtr->MyVector[position] and it has to be (*rdPtr->Myvector)[position]
    Working as fast as I can on Fusion 3

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Clear Screen?
    By tom79 in forum Android Export Module Version 2.0
    Replies: 1
    Last Post: 5th June 2013, 07:37 AM
  2. Would someone be able to clear this up for me?
    By uncleswell in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 22nd January 2011, 02:29 AM
  3. clear screensaver
    By swiftlikeninja in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 12th March 2010, 11:48 PM
  4. Clear Light.
    By Martin_Bodger in forum The Games Factory 2 - Technical Support
    Replies: 3
    Last Post: 14th May 2008, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •