Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:42:48+00:00 2026-05-24T02:42:48+00:00

I need to control the amount to touch points in my application, for this

  • 0

I need to control the amount to touch points in my application, for this I am using a vector container and my basic setup is this:

//--------------------------------------------------------------
void testApp::touchDown(ofTouchEventArgs &touch){
    isTouching = true;

    touchPoints.push_back( ofVec2f( touch.x, touch.y ) );
}

//--------------------------------------------------------------
void testApp::touchMoved(ofTouchEventArgs &touch){
    for ( int i = 0; i < touchPoints.size(); i++ ) {
        if ( touch.id == i ) {
            touchPoints[i] = ofVec2f( touch.x, touch.y );
        }
    }
}

//--------------------------------------------------------------
void testApp::touchUp(ofTouchEventArgs &touch){
    isTouching = false;

    int i = 0;
    for ( vector<ofVec2f>::iterator iter = touchPoints.begin(); iter != touchPoints.end(); ) {
        //int i = std::distance( touchPoints.begin(), iter );
        cout << "i: " << i << endl;
        if ( touch.id == i ) {
            iter = touchPoints.erase( iter );
        }
        i++;
        ++iter;
    }
}

But when I move up a finger the app freezes, so there most be something wrong in the touchUp(), any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:42:49+00:00Added an answer on May 24, 2026 at 2:42 am

    Many things: First off, you cannot modify (erase/insert) a container and expect iterators to remain valid!

    Let’s see. I want to modify touchMove as well:

    void testApp::touchMoved(const ofTouchEventArgs & touch)
    {
      if (touch.id < touchPoints.size())
        touchPoints[touch.id] = ofVec2f(touch.x, touch.y);
    }
    

    Next, the big one:

    void testApp::touchUp(const ofTouchEventArgs & touch)
    {
      if (touch.id < touchPoints.size())
        touchPoints.erase(touchPoints.begin() + touch.id);
    }
    

    Basically touch.id is just the index in the vector, so we can use that directly. To erase an element from the middle, we just call erase on the corresponding iterator. Since vector has random access iterators, we can say begin() + touch.id in constant time.

    Update: Actually I think your code is broken: After you erase an element from the vector, the other elements move up, so you will lose the association between touch.id and the container element! What’s needed is, you guessed it, an associative container:

    struct testApp
    {
      std::map<int, ofVec2f> touchPoints;
      bool isTouching;
    
      void touchDown(const ofTouchEventArgs & touch)
      {
        isTouching = true;
        touchPoints[touch.id] = ofVec2f(touch.x, touch.y);
      }
    
      void touchMoved(const ofTouchEventArgs & touch)
      {
        touchPoints[touch.id] = ofVec2f(touch.x, touch.y);
      }
    
      void touchUp(const ofTouchEventArgs & touch)
      {
        isTouching = false;
        touchPoints.erase(touch.id);
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using this pattern when I need to control how long various async
I'm implementing a custom control and in this control I need to write a
I need to control the amount of concurrent thread's running. I think I need
I have a WizardStep Control from which i need one information: The total amount
I need to control inbound and outbound traffic to/from a linux box from within
I need a control that can list data in 3 columns, I want to
I need GUI control for audio file presentation. The language is not very important
I'm automating Outlook and I need to control who the email appears to be
We need a user control that can show Microsoft Office files (Word, Excel..). There
I need .NET UI control that acts as a designer/editor window similar to what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.