swarm-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[swarm-hackers] Re: Still learning the framework...


From: Nima Talebi
Subject: [swarm-hackers] Re: Still learning the framework...
Date: Tue, 17 Nov 2009 14:50:19 +1100



On Tue, Nov 17, 2009 at 2:32 PM, Nima Talebi <address@hidden> wrote:
Hi All,

This bit of code about to be presented is merely a proof-of-concept (POC) for myself in learning the framework, and specifically the memory zoning.

What I have here, is an attempt to create a new "HeatbugsWorld", which hides details such as....
 * The fact that it "is-a" Swarm
 * it conforms to Grid2d

...and adds a few utility methods, for example...


@class HeatbugsModel;

@protocol HeatbugsWorld
- (HBLength)width;
- (HBLength)height;
- (HBSize)size;
@end

@interface HeatbugsWorld:Swarm <Grid2d> {
    HBSize size;
}

+ (id)createBegin:(id)aZone withModel:(HeatbugsModel *)m andSize:(HBSize)s;
- (HBLength)width;
- (HBLength)height;
- (HBSize)size;

@end


@implementation HeatbugsWorld

+ (id)createBegin:(id)z withModel:(HeatbugsModel *)m andSize:(HBSize)s {
    HeatbugsWorld *this = [Grid2d create:m setSizeX:(int)s.width Y:(int)s.height];
    /*! Now set up the grid used to represent agent position... */
    this->size = s; 
    return self;
}

- (HBLength)width {
    return size.width;
}

- (HBLength)height {
    return size.height;
}

- (HBSize)size {
    return size;
}

@end



...however, that crashes on `[Grid2d create:m setSizeX:(int)s.width Y:(int)s.height];'. The stack & crashlog...

2009-11-17 14:20:40.679 Heatbugs[1157:6807] +[HeatbugsModel allocIVars:]: unrecognized selector sent to class 0xa3b0

2009-11-17 14:20:40.680 Heatbugs[1157:6807] An uncaught exception was raised

2009-11-17 14:20:40.680 Heatbugs[1157:6807] +[HeatbugsModel allocIVars:]: unrecognized selector sent to class 0xa3b0

2009-11-17 14:20:40.682 Heatbugs[1157:6807] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[HeatbugsModel allocIVars:]: unrecognized selector sent to class 0xa3b0'

*** Call stack at first throw:

(

0   CoreFoundation                      0x95a1358a __raiseError + 410

1   libobjc.A.dylib                     0x93460f49 objc_exception_throw + 56

2   CoreFoundation                      0x95a5fa9b +[NSObject(NSObject) doesNotRecognizeSelector:] + 187

3   CoreFoundation                      0x959bb026 ___forwarding___ + 950

4   CoreFoundation                      0x959babf2 _CF_forwarding_prep_0 + 50

5   Swarm                               0x000826bb +[Grid2d createBegin:] + 59

6   Swarm                               0x00080b3c +[Discrete2d create:setSizeX:Y:] + 55

7   Swarm                               0x0008267a +[Grid2d create:setSizeX:Y:] + 73

8   Heatbugs                            0x00006e57 +[HeatbugsWorld createBegin:withModel:andSize:] + 55

9   Heatbugs                            0x00003cf2 +[HeatbugsModel heatbugModelWithAZone:] + 338

10  Swarm                               0x0001e726 +[CreateDrop_s create:] + 41

11  Heatbugs                            0x00003221 -[HeatbugsGUI buildObjects] + 145

12  Swarm                               0x000860e6 -[OpenStepSwarmController newSimulation:] + 211

13  Foundation                          0x98c90964 -[NSThread main] + 45

14  Foundation                          0x98c90914 __NSThread__main__ + 1499

15  libSystem.B.dylib                   0x94800f39 _pthread_start + 345

16  libSystem.B.dylib                   0x94800dbe thread_start + 34

)




1. Scott - based on what you said regarding zones - quite correctly - even a [HeatbugsWorld alloc] would crash - so I've removed all such methods and functions, but now I need to find a way of encapsulating swarm-framework implementation details from the user-app - mostly just to make sure that I can do it - and that I have a good understanding of how it all works.


2. I'm also a little confused with protocols and classes that share the same name - such as Grid2d - is that how things should be done? Is that good practice - should I be doing it? :)


I found this which explains protocol vs class names, so we can ignore question 2 :)....

 

3. Finally, notice that the [Grid2d create:setSizeX:Y:] takes no Zone info, could that be related to my problem?  I did try [[Grid2d createBegin:z] ...] but had no luck there either.


4. Sorry for the unlimited supply of newb-spam.


Nima




--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0

reply via email to

[Prev in Thread] Current Thread [Next in Thread]