• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimer and messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimer and messages


  • Subject: NSTimer and messages
  • From: Baptiste Calmès <email@hidden>
  • Date: Tue, 28 Oct 2003 14:27:04 +0100

Hi all,

I'm pretty new to object programming, so maybe it's a stupid question.

I'm trying to use a timer, so that an point encapsulated in an NSValue is periodically changed. To do this, I set a timer to call a method that changes this value. Unfortunately, my program exits with signal 11 sigsegv. I don't really now what that means. I also noticed that when I try to do the same thing, but without an NSValue (simply changing an NSPoint), there is no problem. It seems to me that the timer cannot use a method that messages to another object than self. Of course, I suppose this is ridiculous, but I cannot find my mistake. Any ideas? Thanks for any tip.

Baptiste

Here is my code: one object class, MyObject, instantiated once in Interface Builder. It crashes exactly in method try, when invoked by the timer, at the line:

myOtherPoint = [myValue pointValue] ;

(when invoked by a simple [anInvocation invoke], there is no problem).

/* MyObject */

#import <Cocoa/Cocoa.h>

@interface MyObject : NSObject
{
NSValue *myValue ;
NSTimer* timer ;
}

- init ;

- (void) try ;

@end

#import "MyObject.h"

@implementation MyObject

- init
{
self = [super init] ;

NSPoint myPoint ;
myPoint.x = 2 ;
myPoint.y = 3 ;

myValue = [NSValue valueWithPoint: myPoint] ;


SEL theSelector ;
NSMethodSignature* aSignature ;
NSInvocation* anInvocation ;

theSelector = @selector( try );

aSignature = [MyObject instanceMethodSignatureForSelector: theSelector] ;
anInvocation = [NSInvocation invocationWithMethodSignature: aSignature] ;
[anInvocation setSelector: theSelector] ;
[anInvocation setTarget: self] ;

printf("first try \n") ;

[anInvocation invoke] ;

printf("succeeded in first try \n") ;

timer = [NSTimer
scheduledTimerWithTimeInterval: 2
invocation: anInvocation
repeats: YES] ;
[timer retain] ;

return self;

}

- (void) try
{

NSPoint myOtherPoint ;
printf("trying \n") ;
myOtherPoint = [myValue pointValue] ;
printf("succeeded: %f %f \n", myOtherPoint.x, myOtherPoint.y) ;
}


@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Recommendation for Testing Software on Jaguar and Panther Systems
  • Next by Date: Max size of an NSString
  • Previous by thread: Recommendation for Testing Software on Jaguar and Panther Systems
  • Next by thread: NSTimer and messages
  • Index(es):
    • Date
    • Thread