Mar 19, 2012

OpenGL ES (Shader) facts #1

- There is no type-casting. Use constructor.
- When declaring float or vec, you must declare its precision, otherwise there would be a compile-time error.
- You cannot multiply float with integer because there is no type-casting.
- There is no left-shift and right-shift.

Stupid path NSBundle pathForResource:

Don't forget to add the file to "Copy Bundle Resources"...

Manual Camera on iPhone

Today I have succeeded at streaming video from camera and showing it on the screen. Also, I have succeeded at manipulating pixels before showing it.

The normal way is to:

1. Write your own AVCaptureVideoDataOutputSampleBufferDelegate.
2. Get CVImageBuffer, which is from CVPixelBuffer
3. Manipulate pixels at their addresses
4. Create CVImageRef from CVImageBuffer
4. setContents of the CALayer with your CVImageRef

This is a normal way. You may also channel CVImageBufferRef to OpenGL in order to manipulate pixels with OpenGL Shader.

The vital technique is not to copy anything but to manipulate the pixels at their addresses directly.

It seems to me that using OpenGL shader is a better idea because:

1. It is run on GPU. This means it does not consume CPU time.
2. It is optimized for parallel stuffs.

I'm too lazy to post the code here.

Mar 12, 2012

Deploying to iOS 4.2.1 problem

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
 
If you found this problem, it is because the OS is copied from your iPod/iPhone, and it does not have the necessary library.
 
In order to solve it, you must copy

/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2/Symbols/Developer 
/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2/Symbols/usr
 
And paste these folders under /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/
.
 
That's it.

DISPATCH_QUEUE_PRIORITY_BACKGROUND in dispatch_async causes EXC_BAD_ACCESS in iOS 4.2.1 and earlier

This is because DISPATCH_QUEUE_PRIORITY_BACKGROUND does not exist.

Please use DISPATCH_QUEUE_PRIORITY_LOW.

!NO is not YES..

Today I have found out that

if (!NO) { ... }

is not working as I expect...

!NO is not a true statement.

NSLog on BOOL with %@ causes EXC_BAD_ACCESS

Just be careful with it!

Use @property

Here is what caused the EXC_BAD_ACCESS, and it took me like 2 hours to solve it.

Notice that _someVar is released twice. It's super confusing.

Next time, just use @property.

And, when I want to release it, just set the property to nil.

You cannot really go wrong with @property...

EXC_BAD_ACCESS with [CALayer retainCount]

EXC_BAD_ACCESS might mean many things.

Normally, it means that you release an autorelease object, release too many times, or use a released object.

Here is the way to debug it.

First of all, you need to turn on NSZombieEnabled. To turn it on:

1. you need to go to "Project -> Set Active Executable (...)"
2. Under the tab "Arguments" and in the box "Variables to be set in the environment", Add a new variable named "NSZombieEnabled" with the value "YES"

Now when you get an EXC_BAD_ACCESS, it will tell you what happens.

One of the scenarios is that you will get [CALayer retainCount].

This means that you release an autoreleased view or a view too many times.

Now you can go find out....

I took like 2 hours to find out that I release a view too many times....

Good luck!