Posts Tagged ‘programming’

…little help (oh, malloc)?

Monday, July 6th, 2009

i’m having a time of it tracking down a resource allocation bloat culprit in an iPhone app i’m working on. i’ve narrowed it down to when i’m rapidly updating the center property of a UIImageView. a snippet from the Instruments application is below:

malloc


there are hundreds (if not thousands) of these messages, and the object allocation graph trends steadily upwards. when i disable the portion of the method which updates the center property the allocations stop and the memory usage goes flat. this also only occurs on the device…the simulator does not exhibit this behavior.

i’m using UIImageView directly, without subclassing, and it contains data from a small PNG file. i’ve patched up several other leaks successfully today, and really wanted to nail this one too.

(overly simplistic) saving state in oF for iPhone

Friday, June 19th, 2009

save_stateThere was a recent comment about saving / restoring application state when using openFrameworks for iPhone which got me to thinking about how to do it. Apple’s frameworks provide a fairly thorough way to save state to the disk and restore later. There seem to be three primary ways to do this: simple plist files (usually encoded in binary on the iPhone), archived data (they like to refer to this as freeze-dried object graphs) and core data.

I believe that archiving objects require methods inherited from NSObject, which we don’t have in openFrameworks’ ofSimpleApp. Core Data seems like overkill, so I looked into using plist files.

There are likely better ways to do this, but this ad-hoc solution works wonderfully for a small app I’m working on, and only requires a bit of Objective-C code that could likely be moved up into a nice wrapper class. However, since the question was asked I’d just like to get it out there before working on a more elegant approach. (more…)

ofxiPhoneAlertView

Wednesday, June 10th, 2009

Here is a (really) basic wrapper for the UIAlertView in openFrameworks of iPhone. Not all of the necessary delegate methods have been implemented yet, but this is enough for me to get the proof of concept rolling in an app I’m building.

Feel free to let me know how I can do things better, or just tinker with the code directly at github: ofxiPhoneWrappers

Check out the example project. This is a bit of a kludge. I would like to figure out how to avoid having to declare main and testApp as mixed source files (.mm). It works for now, however.

Here are the notes on using the class: (more…)

[my] summer of code

Friday, May 22nd, 2009

iconIn preparation for several iPhone application development gigs which have lined up for the summer I’m getting back into my previous projects. Specifically, I’m going to get Follower and Pinwheel ready for release and am looking to push them out to the AppStore in the next month or so.

Also, as an exercise to get working with a web API I’m building an iPhone native client for SHIFD, called Slide. Right now it’s overly simplistic, but I much prefer the native app to the mobile web app. I’m not sure if I’m going to keep it as a learning project or also invest the time and resources to make it another released application.

All this is in service to building out cloudreader.me, the online version of the CloudReader generative text animation project. I’d like to make that something available sometime.

Toy Design: Talking Blocks sketches

Tuesday, April 7th, 2009

sketch_v01_darkAlex and I have been developing the plans for the blocks in preparation for building the prototypes in the next week. For this, I built the community edition of QCad (open source FTW!) and have been teaching myself how to draw with it. There was a bit of a learning curve to the interface and the modal model of the application tools, but I’m now relatively comfortable with the basics. (more…)

counting change

Thursday, March 26th, 2009

ofcountingchange

As an in-class exercise for Spatial Media we were asked to develop a program which would identify coins in a series of supplied images and tally up their total value. In one hour.

Since time was limited, I decided to use pixel count as a rough estimate of each coin’s size. This works very reliably with the sample set of images, but that’s likely because the images consist of duplicated coins and are on a solid white background. Several additional methods wold likely need to be implemented to deal with actual situations. (Code below) (more…)

openFrameworks + iPhone

Monday, March 16th, 2009

particles-iphoneI’ve heard about openFrameworks 0.6 (as of yet unreleased) and specifically efforts to support building apps using oF for the iPhone. There are a few developers who have published videos of their efforts and even several apps in the AppStore.

Memo Atken has a very informative article about setting up the prerelease 0.6 version for use with the ofxiPhone addon. However, there is a HUGE simplification of the steps necessary for getting the supporting libraries installed for use with iPhone.

Update: freetype/freeimage building instructions have been posted. (more…)

Spatial Media: TrafficFlow update

Thursday, March 5th, 2009

Simple updates on the project. The previz applet has mouse control for each of the emitters. It’s interesting to see how the glowing packets influence each other when in close proximity. Here’s the applet.

ir_flame

Camera vision. Started working with openFrameworks to do the visual tracking of objects on the table. Unexposed portions of developed film negatives block most visible light and let IR light pass. Using this as a filter over the built-in iSight camera, I was able to test a rudimentary camera tracking system. It would likely be better to use a more robust library like openCV, but writing the tracking myself helped me to learn about how it works.

Still have to merge these two components. It looks like I’ll have to rewrite the flocking system in C++ since Processing/Java is getting bogged down. Ameya is working on the web side of the project – messing with a linux-based router to handle the proxy and packet sniffing as well as a database system to manage the data.

The table was built throughout this past week; we still need to mount the camera and projector in an effective way for under projection and sensing…any advice?

Simple things feel so good. (warning: geekery)

Wednesday, March 4th, 2009

Toggle an integer variable between 0 and 1. Useful for a flag to control program flow in C without boolean types.

toggleVar = 1>>toggleVar;

What this is doing is right shifting the integer 1 either zero or one place, depending on the current value of toggleVar.

An 8-bit (unsigned – positive values only) integer has 256 possible values. This is a byte of information whose bits can be represented in binary as 00000000. The least significant bit, the smallest values are on the right…so, 00000001 = 1, 00000010 = 2 … 11111111 = 255.

Ok, this isn’t a binary lesson…so, right shifting is simply moving all the bits to columns to the right. 2>>1 = 1 or, 00000010 >> 1 = 00000001 (which is binary for 1).

The expression at the top does exactly this: When toggleVar is zero, it becomes 1>>0 = 1 and when toggleVar is 1 the expression is 1>>1 = 0. The last bit gets shifted right into oblivion!!! (sorry for that).

Of course, with boolean data types toggleVar = !toggleVar is still shorter, by one char! :)

Using Arduino in Xcode

Saturday, February 28th, 2009

While the Arduino IDE (Integrated Development Environment) is relatively simple way to program the Arduino hardware, I found myself getting frustrated by it’s limited features after spending time using Xcode and Eclipse. There are some simple tutorials available online which demonstrate how to set up Xcode for programming the Arduino, however these didn’t “just work” for me, and were targeting arduino-0.10.

I made a few (simple in hindsight) changes to the project which has worked well for me so far. (more…)