Hamish Rickerby

Moving to Melbourne and planning a big project

Error on Line 1987

| Comments

I am having a bit of a play with the cocos2d game engine for iPhone and encountered a very strange error in the console - I don’t believe it’s at all related to the game engine itself, so it’s just coincidence that I was trying something new out.

error while killing target (killing anyway): warning: error on line 1987 of “/SourceCache/gdb/gdb-962/src/gdb/macosx/macosx-nat-inferior.c” in function “macosx_kill_inferior_safe”: (os/kern) failure (0x5x)

I figured out that it had to do with definition of a selector… Naughty code below.

1
2
3
MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
                                        target:self
                                      selector:@selector(startGame)];

The problem is that the method name inside @selector() MUST have a colon on the back of it.

Good code

1
2
3
MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
                                        target:self
                                      selector:@selector(startGame:)];

Hope that’s useful to someone.

User Preferences on iPhone

| Comments

Getting and setting user preferences on iPhone is pretty darn easy.  I was looking for a way to automagically store a users email address between different application sessions, and found the linked tutorial immensely helpful (iphonedevelopertips.com).

I needed to store a string (NSString object actually) however, and the tutorial didn’t help me with that. The NSUserDefaults object has dedicated methods for storing and retrieving BOOL, float, and NSInteger values.  It also has a setObject:forKey: method - which is what I ended up using.  The setObject method handles data of types NSData, NSString, NSDate, NSArray or NSDictitionary - making it incredibly useful indeed.

My Preferences.h

1
2
3
4
5
6
7
#import <Foundation/Foundation.h>
#import "Constants.h"
@interface Preferences : NSObject {
}
+ (NSString *)emailAddress;
+ (BOOL)setPreferences:(NSString *)emailAddress;
@end

My Preferences.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#import "Preferences.h"

@implementation Preferences

/*-------------------------------------------
* Return the users default email address
*-------------------------------------------*/
+ (NSString *)emailAddress {
  NSString *returnValue;
  // If preference exists
  if ([[NSUserDefaults standardUserDefaults] stringForKey:kPreferencesEmailAddress]) {
    returnValue = [[NSUserDefaults standardUserDefaults] stringForKey:kPreferencesEmailAddress];
  } else {
    returnValue = @"";
  }
  return returnValue;
}

/*-------------------------------------------
* Write preferences to system
*-------------------------------------------*/
+ (BOOL)setPreferences:(NSString *)emailAddress {
  // Set values
  [[NSUserDefaults standardUserDefaults] setObject:emailAddress forKey:kPreferencesEmailAddress];
  // Return the results of attempting to write the preferences to system
  return [[NSUserDefaults standardUserDefaults] synchronize];
}
@end

kPreferencesEmailAddress is a constant I’ve defined with the key value of the users email address. It just makes sure I don’t mistype anything.

Key (only) differences between my code and the code at iphonedevelopertips.com are the use of the objectForKey method to set the NSString value, and stringForKey to retrieve the object and cast it to a NSString object.

Hope that helps someone!

Last Days: Woolworths

| Comments

Went into Woolies here in Reading a couple of days ago to see what was left on the shelves. They truly are selling everything. People were literally buying the shelves the remaining products were sitting on. I also saw them offering the tills for £150 - considered getting one so I could play shopkeeper, but no.

Some pics of the carnage

Pretty much everything was gone. Apart from the below fella’s book. Give it up!  People won’t even buy your work when it’s heavily discounted.

Poor Cliff.

That’s not the end of Woolworths for those in the southern hemisphere however.  The brand lives on as a supermarket - I do remember Woolworths being a cheap department/variety store in New Zealand when I was very young, but it transitioned to a supermarket there many years ago.

I won’t miss Woolworths. I only ever bought 1 pair of gardening gloves and a can of “V” from it.

Zazzle Discount Vouchers / Codes

| Comments

I received a package I ordered from Zazzle today and it contained some discount vouchers that I won’t be using. Codes below - tell me if they don’t work so I can update the post to show they are gone.

  • $10 (USD I assume) orders of over $10 or more - expiring 31st Dec 2008 - ZAZZLE10GIFTAYJTRYRM and ZAZZLE10GIFTDFWCINBI
  • $5 off purchase of $50 or more (I reckon this is multi-use) expiring 18th Jan 2009 - ZAZZLEWINTER

Enjoy!

Memory Management in Objective-C

| Comments

I was having some issues with Memory Management and dealloc’ing objects (and subsequently crashing software) and found the following resources very useful:

To paraphrase
  1. Never dealloc, use release
  2. If you create an object it’s your responsibility to release it
  3. If you want to own an object or use and object returned from another object you should retain it
  4. Don’t release an object you didn’t create or own
Now I remember why I like programming languages that take memory management out of my hands. Last time I touched memory management was at university, and it was a pain then too.
Good thing is that Objective-C/Cocoa has those simple rules/conventions to follow.  Memory Management is not onerous on the mac/iPhone, so I can’t complain too much.

Dodgy Supermarkets

| Comments

Sainsburys have X-rated cereals apparently. I didn’t see any actual X-rated material though.

Sign saying \

Tescos however did have X-rated food, but did not have a warning like Sainsburys did.

Island Pride brand Cock Soup (aka Chicken Soup)

Firefox 3.0.3 and 500 Internal Errors With Javascript

| Comments

I had a very confusing situation today with a multipart form that was for uploading a picture to a new web service I’m working on.

In Safari the form upload worked. Even in Internet Explorer 6 the form upload worked (after I fixed the dodgy MIME-type that IE passes through for JPG images - image/pjpeg for those interested).

The form I was trying to submit had the multipart attribute set correctly, and also had some javascript to disable the file selection, form submission button, and show a spinner to indicate that something is happening, and they don’t try and submit the file twice if they’re sending in a large image.

My submit tag orginally looked like this (Ruby on Rails)

1
&lt;%= submit_tag 'Upload Photo', :class =&gt; "formbutton", :id =&gt; "submit-button", :onClick =&gt; "$('upload-form').submit();Form.disable('upload-form');Effect.toggle('footnote', 'appear', {duration: 0});Effect.toggle('spinner', 'appear', {duration: 0});" %&gt;

I was very confused as it did work in those other browsers, but not in Firefox.

The key to fixing this was to add return false; to the end of the javascript statement…

1
&lt;%= submit_tag 'Upload Photo', :class =&gt; "formbutton", :id =&gt; "submit-button", :onClick =&gt; "$('upload-form').submit();Form.disable('upload-form');Effect.toggle('footnote', 'appear', {duration: 0});Effect.toggle('spinner', 'appear', {duration: 0});return false;" %&gt;

What I find particularly confusing about this is that everything I read on the “return false;” statement leads me to believe that this form should not be submitted - however - return true does not work (500 Internal Server Error returned). But what the hey - it works.