Doc Issues When Installing New Gem

Posted by Tres Sat, 02 Jan 2010 07:50:00 GMT

Always the little things, right?

So you’re installing a new Gem & everything seems to be going okay. You see:

Building native extensions.  This could take a while...
Successfully installed ilovemystuff-lib-0.3
1 gem installed

But immediately after you see what looks like success, you see a bunch of messages like this:

module 'xXxxx' for module Xxxx not known
Enclosing class/module 'xxx' for class Xxx not known
...

Well, just make sure you’ve got an updated version of rdoc installed & that should clear things up:

gem install rdoc

Done!

Posted in ,  | Tags , , , ,

Converting Sounds For iPhone

Posted by Tres Wed, 15 Jul 2009 20:10:00 GMT

To convert sounds from other formats to the recommended caf format use:

afconvert -f caff -d LEI16 <infile> <outfile>

Posted in , ,  | Tags , ,

Updated: Easy Way to Get a UIActivityIndicatorView to startAnimating Before Starting an NSURLConnection sendSynchronousRequest

Posted by Tres Sun, 24 May 2009 04:17:00 GMT

<edit> I can’t really recommend using this method because it locks up the UI for the entire time it runs. If you’re interested in allowing your user to still have access to controls during the time it takes to load, I’d recommend taking a look at NSThread detachNewThreadSelector: toTarget: withObject:. Not only will it make for happier users, but another thread means that UIActivityIndicatorView works without any hacks.</edit>

The problem with running an NSURLConnection sendSynchronousRequest: is that the request runs in the same thread as the main run loop, so esentially for the duration of your request and the server’s response nothing happens that the user can see. No problem, right? Just light up an activity indicator and let your user know that magic things are happening. The only problem is that the activity indicator never shows up until about microsecond before it’s hidden again. Essentially it never appears.

This happens because the is the app never gets back to the UIKit runloop in between calls to the UIActivityIndicatorView.

Now you could send the request in another thread and be done with it. Thread programming is fun and everything, but if you don’t have to manage another thread, why? You can get let UIKit set up your interface before locking everything up by using NSTimer.

    NSTimer *delayTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector(myURLLoadingFunction) userInfo:nil repeats:NO];

Yeah, it’s a hack, but it works. And it doesn’t incur the hazards of using multiple threads.

Posted in ,

Finding The Source of Autorelease EXC_BAD_ACCESS Errors Using gdb & XCode

Posted by Tres Sun, 24 May 2009 01:56:00 GMT

So you’re seeing EXCBADACCESS messages in gdb and your stack trace includes an attempted autorelease that traces back to main without a hopping into a method or class otherwise. This, my friends, is what happens when we try releasing memory that’s already been released.

Finding the source of an attempted bad memory release is a difficult task unless you build your app with the following environment variables:

NSDebugEnabled
MallocStackLogging
NSZombieEnabled
MallocStackLoggingNoCompact

All it takes is setting all of these to YES in XCode (double-click the app in the Executables group of your project Groups and Files, then go to the Arguments tab. Variables are set in the bottom portion of the dialog.)

Once you’ve got the environment variables in place, build normally & then when the app crashes, find the PID of the app and the memory address attempting to be accessed. Then use mallochistory to trace things back to their source. You can do this right from gdb like this: shell mallochistory [PID] [memory_address].

Example:


[Session started at 2009-05-23 18:29:16 -0700.]
2009-05-23 18:29:16.951 MensaMaster[65026:20b] *** -[CFString release]: message sent to deallocated instance 0xee30f0
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".Undefined command: "NSZombieEnabled".  Try "help".
Undefined command: "NSZombieEnabled".  Try "help".
Setting environment variable "NSDebugEnabled" to null value.
NSZombieEnabled
MallocStackLogging YES
Attaching to process 65026.
(gdb) shell malloc_history 65026 0xee30f0

I’ve highlighted the gdb output in red that needs to be used in malloc_history.

Now you can also use Instruments to accomplish the same task, but I leave that for another post.

Time to get back to work.

Posted in ,  | Tags ,

NSLog is Not Your Friend On The IPhone

Posted by Tres Fri, 08 May 2009 06:35:00 GMT

While using the simulator to test and debug an IPhone app, NSLog does nothing to alter the performance of the app. So, if you’re like me, you may just leave all those NSLog calls in – even after they’re no longer serving a purpose. This is a twofold problem. First, and most evident, you’ll see a marked decrease in performance once you get the app on the IPhone. The decreased performance is actually a symptom of the second problem – all of those NSLog messages are being pushed to the device logs, no matter whether you’re compiling a ‘Debug’ or ‘Release’ build. So anyone installing your app will be able to see all your nice little debug messages too.

So I still like you, NSLog. Really. We go too far back to let something like this come between us. We just can’t be seen in public anymore.

Posted in ,  | Tags , ,

UIScrollView Not Scrolling When UIView Subclass Added

Posted by Tres Tue, 05 May 2009 03:45:00 GMT

So UIScrollView doesn’t take care of seeing how large the objects in it are. To make sure UIScrollView scrolls when adding to a view / views that are in the UIScrollView, you need to tell it how big the content is. You can do that with setContentSize: like this:

[scrollView setContentSize:CGSizeMake(myUIViewObject.frame.size.width,
    myUIViewObject.frame.size.height+140)];

Posted in ,  | Tags

Constructor for UIView

Posted by Tres Thu, 30 Apr 2009 23:24:00 GMT

So you’re trying to initialize your UIView and have found various conflicting sources of information on Google & a lack of clear documentation in the Apple API documentation?

Contrary to the boilerplate code included by XCode, initializing a UIView isn’t a matter of calling initWithFrame:. Instead, try initWithCoder: as shown here:

- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        [self initializeBlablah];
        [self setBrainzaiWithStuff: stuff];

    }
    return self;
}

Good to go!

Posted in , ,  | Tags

Forcing Landscape Orientation on IPhone

Posted by Tres Mon, 06 Apr 2009 18:59:00 GMT

This is pretty easy, but it’s also easy to mistake setting default orientation with the ability to display in multiple orientations via the call to shouldAutorotateToInterfaceOrientation in your view controller.

To force your app into a landscape view on start, use info.plist to define the default orientation. Define the key UIInterfaceOrientation and the value UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight

Posted in  | Tags ,

Facebook Development wmode=transparent Flash Woes With Firefox on Windows

Posted by Tres Sat, 21 Mar 2009 08:51:00 GMT

So if you’ve done any Facebook development, you know that every little achievement is a real victory. It’s a grueling, punishing process of doing something the way you would normally do it, then doing it all over again the FBML/FBJS way, or doing the FBML way while all the while knowing it would have taken 10 minutes if only this tag were available, or five minutes if jQuery were available (Nothing like going back to Ajax() to get stuff done). It’s fun in some ways – you get to appreciate the small things again. Heh… I can’t believe I just wrote that.

Our first apps were web apps using Ruby on Rails and Facebooker and integrated Flash elements into the entire experience. The end results took over three times as long as we had estimated, and were truly disappointing. The silver lining were the lessons we were able to learn. One of the big lessons was that we weren’t going to try dealing with FBML / FBJS issues on top of browser variation issuses on top of everything else.

So for our new batch of applications, I decided to go pure Flash. The overall user experience is better, the development time was right on schedule, and we’re pretty happy with the result. Everything has gone smoothly EXCEPT for the one place where we’re using FBML. I mean, it’s appropriate because this is really the ONLY fb tag that we’re using, and it still caused issues.

So by default the <fb:swf> tag uses wmode=transparent, which causes issues in Firefox if your window happens to run outside of the viewable area for the browser. In other words, if they have to scroll to see the bottom of the application only in Firefox and only on Windows, the mouse coordinates get all hosed.

Luckily the guys over at at Facebook allow you to use wmode=transparent|opaque|window, but transparent is the default. So just pick the correct mode for your Flash app & be on your merry way.

Posted in , ,  | Tags , , ,

Use Caution When Sending Boolean Values Via XML to E4X and Actionscript 3

Posted by Tres Thu, 19 Mar 2009 05:12:00 GMT

Okay, all hyperbole aside, passing boolean values via XML will cause problems if you’re not using integer values for your booleans. E4X will happily pass string values “true” and “false” to your function, which will always interpret the non zero value of the string to be true.

So, you’ve got two easy options: either convert the boolean to an integer server-side and cast it to a boolean in Actionscript, or handle it using string value comparisons in your Flash app.

I’m partial to trouncing as little as possible on the XML being generated server-side, so a little:

var localBool:Boolean = (xml.value == "true");

and we’re all done.

Posted in ,  | Tags , ,

Loaded SWF Keeps Reloading in Flash

Posted by Tres Fri, 06 Mar 2009 04:02:00 GMT

So I’ve been working on a loaded SWF – pretty easy stuff with Actionscript 3 – just use Loader() and go, right?

Well, I found out the hard way that the namespace of the Document Class for a loaded SWF is not so separate as you’d like to think. So if you happen to use the same name for your Document Class in both the loader and the loaded SWF, you can count on the loader’s Document Class being run over again once the loaded SWF has completed loading.

So if you’re like me & you’re coming from Java or another C based language that uses Main as the run loop, you can count on some funky behavior; the problem is that Flash is calling Main() when the loaded SWF is downloaded and is hitting Main() in the loader.

It’s always the little things, right?

Posted in  | Tags ,

Creating A New Remote Git Repo

Posted by Tres Tue, 03 Mar 2009 09:12:00 GMT

I have to say it again.

I don’t heart Subversion.

Not anymore, anyway; after pushing Subversion on everyone for everything – and I mean everything (even things like Cfengine input file distribution and storage of corporate document templates), I tried something new last year; and once you go Git, you never go back. It’s not really Git itself that makes me ogle, but how much better the concept of a distributed RCS is than the SVN/CVS model. It’s so much more versatile and easy to use. Way back when, I compared the move from SVN => Git to the move from procedural programming => OOP. Both have that ‘aha!’ moment when you just have to admire the genius of the guys who envisioned them. These days, I liken Subversion to the DOS prompt; it’s adequate if you have the patience and are willing to work around all its shortcomings.

Anyways, here’s the goods on creating a remote repository to push stuff to:

First you’ll need to set up an empty repository on the machine you’re going to be pushing to. Find the directory you want to keep the repository in and then:

git init

Then set up your development box to push to the location you just set up. cd to the directory where you’ve got your git repo and:

git remote add gumby ssh://gumby.brainzai.com/work/brainzai.com/Brainzai/SupaStah

We’ve named our remote repository server ‘gumby’ here.

Now we can push everything to the remote server:

git push gumby master

And Bullllamm! It’s Done!

Posted in  | Tags , ,

iconv Problems When Running rake Tasks

Posted by Tres Fri, 27 Feb 2009 01:45:00 GMT

If you’re trying to run rake tasks & seeing errors like this:

rake --trace db:migrate
...
rake aborted!
no such file to load -- iconv
...

Chances are, you’re running FreeBSD.

The fix is a simple

sudo portinstall converters/ruby-iconv

Posted in , ,  | Tags

Flash Error 5005 Unknown Error Optimizing Byte Code -- UPDATED

Posted by Tres Mon, 09 Feb 2009 20:56:00 GMT

When working on a larger project with Actionscript 3 I started seeing this error while building.

The appearance of the error was related to a new class I was writing & when debugging, the error consistently occurred when certain lines in the new class were not commented & wouldn’t happen when they were.

This is a nightmare scenario for me… ye olde ‘unknown error.’ I began to have the sinking feeling that I had stumbled upon some deep bug that would halt everything & I’d spend the next hours trying to find some workaround… and then I could only hope that it wouldn’t happen again.

A simple restart of Flash got things running right again.

Update:

Turns out that the restart didn’t solve the problem. It helped, but I was still seeing the error cropping up.

To fix the problem you’ve got to set the JAVATOOLOPTIONS environment variable to ‘-Xmx1024M’

To set this on OS X, just point your property list editor to ~/.MacOSX/environment.plist. If you’re not showing hidden files in the Finder, you can do this via the shell with the following:

open ~/.MacOSX/environment.plist 

then create a new item. Set the key to

JAVA_TOOL_OPTIONS

and set the value to

-Xmx1024

To make this active, you’ll need to log out and log back in.

Posted in ,  | Tags , , , ,

MySQL Gem Installation Under RedHat Enterprise Linux

Posted by Tres Mon, 03 Nov 2008 09:34:00 GMT

Installing the mysql Gem under RHEL/CentOS requires you to specify where MySQL is installed. Just point Gem to the mysql-config bin & you’re good to go:

gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Posted in , , ,  | Tags , , ,

Older posts: 1 2 3 ... 7