Cocoa, Flicker with animation when overlaying a NSWindow on a QTMovieView - objective-c

In a project that I am currently working on I have an transparent NSWindow overlayed on a QTMovieView. At certain points I slide a custom view into this child window with animation so that it is displayed over the movie for a short period of time. The only odd behavior is that the animation is smooth on a Mac Book Pro but on a Mac Book(Same OS-X Version) there is significant flicker. The flicker only occurs on the portion of the window that has the actual QTMovie behind it.
Has anyone seen this behavior before or found a way to work around it?

The older MacBooks don't have real video hardware and used shared memory, so it's probably an issue with a slow video card trying to update # 30fps. Have you tried smaller movies to see if the issue goes away?
You may be better off with a pipeline like in the QTCoreVideo101 sample code from Apple. That would be a bit more work, you'd have to take care of the animation yourself, but you would get ultimate control over what is being drawn.

Related

Unexpected behavior after zooming into a 3D object with OrbitControls + Three.js

So, I have this code. It's a small 3D scene with a ground, a red box, a custom loaded building and a rotating "sun". I'm delegating camera navigation to OrbitControls script, as it fits the most the way I want the camera to behave, however, there is a little weird problem: after I zoom in into a 3D object within this scene, rotate a little, then zoom out to "leave" the object, the zoom out process takes a billion scrolls. It's a weird behavior and I'm sorry if I'm not clear enough; once I'm in I have to scroll like forever, and every frame it seems to move "out of" the object very slowly, like the camera state is somehow screwed up.
I'm sorry if this very question has been already asked, I looked for this issue and tried stuff from other topics that seemed the same, but it didn't work.
#Edit
Wow, something even weirder. I tested zooming in this example, indefinitely, then the zoom in started to grow VERY slowly (just like in my code). Am I misunderstanding something? It looks as if the amount of zoom-in's somehow blocked rendering or something.
WestLangley tip actually solved my problem. Setting minDistance prevented the camera to zoom in infinitely, despite the actual rendering only showing a small step into the scene.

UIView animateWithDuration: slows down animation frame rate

I am using CADisplayLink to draw frames using the EAGLView method in a game at 60 times per second.
When I call UIView animateWithDuration: the framerate drops down to exactly half, from 60 to 30 fps for the duration of the animation. Once the animation is over, the fps rises instantly back up to 60.
I also tried using NSTimer animation method instead of CADisplayLink and still get the same result.
The same behavior happens when I press the volume buttons while the speaker icon is fading out, so it may be using animateWithDuration. As I would like to be able to handle the speaker icon smoothly in my app, this means I can't just rewrite my animation code to use a different method other than animateWithDuration, but need to find a solution that works with it.
I am aware that there is an option to slow down animations for debug on the simulator, however, I am experiencing this on the device and no such option is enabled. I also tried using various options for animateWithDuration such as the linear one and the user interaction, but none had an improvement.
I am also aware I can design an engine that can still work with a frame rate that varies widely. However, this is not an ideal solution to this problem, as high fps is desirable for games.
Has someone seen this problem or solved it before?
The solution to this is to do your own animation and blit during the CADisplayLink callback.
1) for the volume issue, put a small volume icon in the corner, or show it if the user takes some predefined touch action, and give them touch controls. With that input you can use AVAudioPlayer to vary the volume, and just avoid the system control altogether. you might even be able to determine the user has pressed the volume buttons, and pop some note saying do it your way. This gets you away from any animations happening by the system.
2) When you have an animation you want to do, well, create a series of images in code (either then or before hand), and every so many callbacks in the displayLink blit the image to the screen.
Here's an old thread that describes similar drops in frame rate. In that case, the cause of the problem was adding two or more semi-transparent sprites, but I'd guess that any time you try to composite several layers together you may be doing enough work to cut the frame rate, and animateWithDuration very likely does exactly that kind of thing.
Either use OpenGL or CoreAnimation. They are not compatible.
To test this remove any UIView animation, the frame rate will be what you expect. Add back UIView animation, it will drop to 30fps.
You said:
When I call UIView animateWithDuration: the framerate drops down to exactly half, from 60 to 30 fps for the duration of the animation. Once the animation is over, the fps rises instantly back up to 60
I dont know why your not accepting my answer, this is exactly what happens when you combine UIView animation with CA animation not using a UIView.

Objective C iPad Animation with large images - What method to use?

I'm trying to build a weather application on the iPad but it seems that I need some help in animation. Say I'm animating a Radar, so the radar source files have 10 gif/jpeg pictures in 900x700 pixel size. I've tried the UIImage animation technique using the tutorial here:
http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/
but it seems that loading 10 images that big is too much for the iPad to handle and its crashing due to memory warnings. I'm researching other techniques to animate but I can't seem to find something that will do this efficiently.
I've looked at others like Core Animation using sprites, and Cocos2D with sprites. Can someone point in the right direction the best way to animate these big images? (keep in mind that these images are dynamic and changes often so the sprites will have to be recreated on a server and fetched from the iPad to do the animation). Thanks
OpenGL only creates textures with dimensions at powers of 2. In the case of your images, that's 1024x1024, which is a meg of memory per image. Still, that shouldn't be a problem with the iPad.
First, investigate using Xcode's profiling tools to ensure the images aren't being repeatedly loaded into memory at each loop of the animation (likely by way of new objects that aren't sharing cached textures). That could solve your problem from the start.
Second, I recommend using Cocos2D if only for the easy handling of textures and caching. Toss the images into a CCAnimation, pop that into a CCRepeatForever, run it with a CCSequence. When you're done hit CCTextureCache to release unused textures.
Third, lower your animation framerate to 30 or less (if only for this animation). It may be the iPad, but you making a weather app. Not a video game.
Finally, downgrade the size of your image. Justify all you want, but a large radar animation will not sell your app. And just because a website might already be playing that animation beautifully, remember that a desktop has vastly more memory and power than any smart phone.
Try breaking the animation image into into smaller parts and animate those instead by treating each components as sprites. It would be best if you use primarily code (CoreGraphics) and draw your radar "by hand" instead of just using images as if they were animated GIFs.

maskToBounds:YES affecting scroll performance

I have several UIButtons on a UIScrollView. I want the buttons to have rounded corners, so I call maskToBounds: on each of them. When I do this and run on the device, the scrolling framerate is pretty bad (it works fine on the simulator). Any ideas on a workaround for this problem?
You're causing the view to be composited offscreen with that call to masksToBounds:, which slows things down quite a bit. Are you rendering custom button images? If so use UIImage -stretchableImageWithLeftCapWidth:topCapHeight: with an image which is the minimum width to encompass it's rounded edges. This allows the GPU to handle stretching the image in the most efficient way possible, while still giving you a button made out of an image. There is a session in the WWDC 2011 videos on Drawing in UIKit - watch that, as it addresses exactly this problem, and a few others you're likely to have.
A few alternative methods:
Tweeties implementation of fast scrolling, by drawing everything manually
Matt Gallaghers implementation of custom drawing. This is the method I use, as it's easy to maintain

Unload image of UIImageView thats offscreen

I'm coding an application on Ipad, in a certain point of my application I present a ViewController with the presentModalViewController.
My ViewController is a UISScrollView who take the larger of the modalView and inside it I display some images, I allow pagingEnabled so I can see all my images inside the scrollView.
Sometimes I have to display more than 10 images inside the scrollView, so I have this error
RECEIVE MEMORY WARNING LEVEL=1 after this one RECEIVE MEMORY WARNING LEVEL=2 and finnaly the debugger exited due to signal 10 (Sigbus).
What can I do? is there a way to unload the image thats offscreen? or others things to do?
Thanks,
I guess you're adding all the images to the UIScrollView? Then the iPad has to keep all 10 images in memory. If they are full screen images, each of them will take up about 3 MB of memory, so you're using 30MB just to keep the 10 images in the scroll view.
You should only add the one or two images that are actually visible. Once they scroll out of sight, remove the UIImageView from your UIScrollView (and make sure you don't retain it anywhere else so it can be deallocated). When a new image scrolls into sight, add it to the UIScrollView only then.
In your UIScrollViewDelegate method -scrollViewDidScroll: get the current contentOffset and use that to calculate which images are visible.
Actually, this problem is even worse on the iPhone 3G, which can't even manage to display two full size photos (taken with it's own camera) at the same time.
If you can make the photos smaller ahead of time by resizing them (server side if you're snagging them from your own services, or client side if they're somehow generated on the device or retrieved from third party services), you should. They will load faster, and you can put more of them on the screen at once without running into memory issues.
The Three20 library has a really great photo-browsing control for the iPhone. I'm pretty sure they only have three photos around at any given time... the photo you're looking at, and the photos going forward or backwards.
http://github.com/facebook/three20
I also think there is an iPad branch of the Three20 controls (at ./tree/ipad), although I don't know if they include the photo browser or not, and haven't tried them yet myself... maybe that's an option for you if you don't want to spend a lot of time on that particular feature of your application. If the iPad photo browser isn't done maybe you could just adapt the iPhone version to suit your needs (shouldn't be hard).
If you want to bake the feature yourself, I'd take some inspiration from the UITableViewController. Your controller should come with associated datasource and delegate protocols to retrieve photos and respond to user events. The controller base class itself should reuse three UIImageViews and should shuffle those around to create the illusion that the user is scrolling through a large list.