Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-23-2010, 04:11 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default Exception with touches set...

Hi there!

I'm trying to get multitouch working in my app but when there's more than one finger on the screen the app crashes when trying to access them. In touches moved, if number of touches is higher than 1 (so there are at least two fingers in the screen) the app tries to access the two fingers, but throws an NSException error. Here's the code and after it the error:

Code:
Code:
// In touchesMoved event

NSLog(@"Touches:%d",[[event allTouches] count]);

if ([[event allTouches] count] > 1) {
	for(UITouch *t in [touches allObjects])
	{
		NSLog(@"Luke, I'm your father!");
	}
			
	UITouch *t2 = [[touches allObjects] objectAtIndex:1];
	CGPoint touchPos2 = [t2 locationInView:t2.view];

	(...irrelevant code...)
}
And here's what I get in the console:
Code:
2010-02-23 10:04:23.694 provaObjectes3D[1909:207] Touches:2
2010-02-23 10:04:24.106 provaObjectes3D[1909:207] Luke, I'm your father!
2010-02-23 10:04:24.130 provaObjectes3D[1909:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
2010-02-23 10:04:24.157 provaObjectes3D[1909:207] Stack: (
    853417245,
    845594132,
    852966195,
    852966099,
    871671569,
    871826727,
    13227,
    818194628,
    818192276,
    818173840,
    818172052,
    834382224,
    853165355,
    853163039,
    834376564,
    817839152,
    817832496,
    9127,
    9060
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
kill
So seems that just the first object position is accessible... However, count says that there are two objects... Argh, it have no sense! :S

Any help please? Thanks in advance!
Johanovski is offline   Reply With Quote
Old 02-23-2010, 04:25 AM   #2 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Default

Try not switching back and forth between touches allObjects and event allTouches.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 02-23-2010, 04:41 AM   #3 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

Hi Mr. Jack!

I've tried this but the problem is that by using "[touches allObjects]" the counter is always one, so seems that there's only one finger on the screen, but by using "[event allTouches]" I can't compile because I can't access to the touch via the "[[event allTouches] objectAtIndex:n]" method...

I've tried replacing all my code by the "[touches allObjects]" and the result is:

Code:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	if ([[touches allObjects] count] > 0) {
		// Hi ha 1 dit a la pantalla
		
		UITouch *t1 = [[touches allObjects] objectAtIndex:0];
		CGPoint touchPos1 = [t1 locationInView:t1.view];
		CGPoint touchPosAnt1 = [t1 previousLocationInView:t1.view];
		
		NSLog(@"1");
		
		if ([[touches allObjects] count] > 1) {
			// Hi ha 2 dits a la pantalla
			
			NSLog(@"2");
	
			for(UITouch *t in [touches allObjects])
			{
				NSLog(@"Luke, I'm your father!");
			}
			
			UITouch *t2 = [[touches allObjects] objectAtIndex:1];
			CGPoint touchPos2 = [t2 locationInView:t2.view];
		}
	}
}
And the console shows:

Code:
2010-02-23 10:36:49.175 provaObjectes3D[1996:207] 1
2010-02-23 10:36:49.331 provaObjectes3D[1996:207] 1
2010-02-23 10:36:49.354 provaObjectes3D[1996:207] 1
(repeat ad infinitum...)
So seems that counter is never > 1...

Any clue about this?
Johanovski is offline   Reply With Quote
Old 02-23-2010, 04:53 AM   #4 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

Solved!

You were on the right way, Mr. Jack!

What I've done is to simply create a new NSSet from the event (to ensure that initial data won't be modified during the method) and then everything worked! Here's the new code:

Code:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	NSSet *touchSet = [event allTouches];  // <--- This is the happy line!
	
	if ([touchSet count] > 0) {
		// Hi ha 1 dit a la pantalla
		
		UITouch *t1 = [[touchSet allObjects] objectAtIndex:0];
		CGPoint touchPos1 = [t1 locationInView:t1.view];
		CGPoint touchPosAnt1 = [t1 previousLocationInView:t1.view];
		
		if ([touchSet count] > 1) {
			// Hi ha 2 dits a la pantalla
	
			for(UITouch *t in [touchSet allObjects])
			{
				NSLog(@"Luke, I'm your father!");
			}
			
			UITouch *t2 = [[touchSet allObjects] objectAtIndex:1];
			CGPoint touchPos2 = [t2 locationInView:t2.view];
		}
	}
}
Thanks for your time Mr. Jack!
Johanovski is offline   Reply With Quote
Reply

Bookmarks

Tags
multitouch, sigabrt, touch, touches

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 270
21 members and 249 guests
ADY, Alsahir, Dani77, e2applets, iph_s, JasonR, keeshux, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, Rudy, sebasx, sly24, timle8n1, Touchmint, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,759
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0