Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Doc Block
Apr 15, 2003
Fun Shoe

Hog Obituary posted:

Ah, thanks, so [self retain] or strongPointer=self is accepted practice for these kinds of things? Because that actually seems considerably more reasonable, but still weird.

Well, B is a long-lived object and A is a short-lived object, and we're talking about A's internal cleanup, so I think it makes more sense for A to clean himself up when the task is done.

I'm actually okay with [self retain], I think I used to have some hangup about it because it feels like you're just creating a retain-loop and it'd be a recipe for memory leaks. I suppose you just need to be vigilant about releasing self.

I've done it once or twice, and seen other people do it. Try to design your classes so you don't need to, but sometimes it can't be helped and is worth the extra safety.

With [self retain] you just ido [self release] when you're done. Remembering should be easy enough since in this case it's going to be in the same method as the [self retain].

With ARC you assign self to a strong pointer and then use the strong pointer in place of self, to keep ARC from seeing that you don't use the strong pointer any further and immediately releasing it (and prevent it from being optimized out entirely).

Doc Block fucked around with this message at 07:55 on May 19, 2012

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Sorry I meant the short-lived object's -dealloc. Presumably it will be deallocated shortly after the delegate call that results in its no longer being held on to by its delegate.

Doc Block
Apr 15, 2003
Fun Shoe
Yeah, he should be doing the cleanup in the short-lived object's -dealloc, but sometimes you can't avoid doing it this way.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Usually the best pattern is for there to be a very clear hierarchy of ownership and a very clear stage of teardown that originates from the owner. Even putting memory safety aside, if an event is propagating up from a child, the parent immediately tearing things down is going to leave that portion of the tree in an inconsistent state when control returns to the child. Instead the parent should say "hmm, come back to me after this operation is done and I'll tear all this down", e.g. by dispatching a block to do that on the current queue.

Pseudo-God
Mar 13, 2006

I just love oranges!
What is the simplest way for a non-US resident to sell apps in the US app store? Can a foreigner of any country register without a problem, or are onpy certain countries allowed? Would I have to pay US income tax?

Doc Block
Apr 15, 2003
Fun Shoe
As far as I know, anyone from just about any country can sell apps in the US app store. I've got a few apps that were developed by people/studios from other countries.

If the US has a tax treaty with your country, you can just pay income tax in your home country. You may need to file paperwork to make that official. Aside from sales tax (which Apple will add on and collect for you) Apple doesn't withhold any money for taxes.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
So I'm curious: how's everyone liking storyboards?

I've only used them on a couple apps and I find two things: I'm writing more code than I was without storyboards; and after about the fourth view controller on the storyboard I start to get lost and frustrated zooming the editor in and out. Storyboards feel promising but they don't yet offer me much. Maybe I'm missing some compelling feature?

haveblue
Aug 15, 2005



Toilet Rascal
Is there some secret functionality attached to the keystroke ctrl-T that I'm not aware of? I'm trying to catch a string of characters with ctrl held down but holding control and pressing T does not deliver a key event to my window. This is the only key I've tried so far of which that's true. What does pressing ctrl-T do, and is there a way to bypass it so I can run my own code in response?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Testing syntax highlighting.

Objective-C code:
- (void)parseNodes:(NSArray *)nodes
{
    [nodes enumerateObjectsWithOptions:(kNilOptions) usingBlock:^(id node, NSUInteger idx, BOOL *stop) {
        GCTag *tag = [GCTag rootTagWithCode:[node gedTag]];
        Class objectClass = [tag objectClass];
        
        if ([objectClass isEqual:[GCHeader class]]) {
            if (_header) {
                NSLog(@"Multiple headers!?");
            }
            _header = [GCHeader headerWithGedcomNode:node inContext:_context];
        } else if ([objectClass isEqual:[GCEntity class]]) {
            [_entities addObject:[GCEntity entityWithGedcomNode:node inContext:_context]];
        } else if ([objectClass isEqual:[GCTrailer class]]) {
            *stop = YES;
            return;
        } else {
            NSLog(@"Shouldn't happen! %@ unknown class: %@", node, objectClass);
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (_delegate && [_delegate respondsToSelector:@selector(file:updatedEntityCount:)]) {
                [_delegate file:self updatedEntityCount:[_entities count]];
            }
        });
    }];
    
    //TODO verify that node count == entity count, ie that no data came after trailer. how to react?
    
    if (_delegate && [_delegate respondsToSelector:@selector(file:didFinishWithEntityCount:)]) {
        [_delegate file:self didFinishWithEntityCount:[_entities count]];
    }
}
Hmm, better than nothing, I guess.

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

If memory serves, ARC is only supported on iOS 4.3 and up, not 4.2.


What is an "overlay" sprite? Also, make sure you're only changing this sprite's transparency, not the layer's.

Yes, I'm only changing the sprite's transparency. The overly sprite is a tiny sprite that get's scaled to the screens size so a half-transparent texture is put over everything except for a few buttons so everything else appears darker.


Doc Block posted:

If memory serves, you're using a really old version of Cocos2D, right? Which means you probably started from the really old Cocos2D project template, right? Maybe the old template didn't have any of the multitasking methods in the app delegate.

Make sure you're pausing and unpausing the scheduler in the appropriate multitasking methods in your app delegate.

applicationWillResignActive: should call pause on the director (if the director in your old version of Cocos2D has such a method)

applicationDidBecomeActive: should call resume on the director

applicationDidEnterBackground: should call stopAnimation

applicationWillEnterForeground: should call startAnimation

applicationSignificantTimeChange: should call setNextDeltaTimeZero:YES on the director

All I'm doing differently is changing the pixel format to kEAGLColorFormatRGBA8. When I change it back to kEAGLColorFormatRGB565, the problem no longer occurs.

Doc Block posted:

This is because RGBA8 means your OpenGL ES framebuffer is 32-bit RGBA, meaning it supports the framebuffer itself being transparent. You'll note that the RGB565 pixel format has no mention of an alpha channel, hence you cannot get a transparent framebuffer when the pixel format is RGB565.

Keep in mind that your app is rendering to an OpenGL ES framebuffer object, which the GPU then composites with whatever else it's supposed to display. If you have stuff in your view hierarchy that sits underneath your OpenGL ES view, and your OGL ES framebuffer has parts that are transparent, the stuff underneath will show through.

What effect are you trying to achieve? edit: nevermind, saw that you're trying to make the background transparent. What is supposed to be showing through?

What I'm trying to show through is showing through fine. It sounds strange, but it's my own custom parallax background class made outside of Cococs2D. The reason I felt like I needed this is because I wanted preserve the parallax while Cocos2D does scene transitions which slides the last scene off the screen while a new one is dragged on. Using the Cocos2D parallax background I couldn't achieve this correctly because the new parallax background would be overlapping the old one. I tried syncing them, but it just became a mess. Performance is great with my new parallax class, and the frame rate in Cocos2D isn't hindered at all. I also have my own gradient background behind that which I can do a lot more with than the Cocos2D.


But anyway, still having problems. By the way, I'm using Cocos2D 0.99.5.

mahill
Dec 29, 2006
Question about feasibility here...

I'm a mentor for a high school FIRST Robotics team. We go to competitions to go against other robots like ours. Scouting out what other robots can do is an important part of strategy, and I'd like to use iPads to accomplish this. There are usually (depending on the year) 6 robots competing against each other every match, so I'd like to use 1 iPad per robot and a host laptop for them all to connect to. Unfortunately, the robots are connected wirelessly to the drivers via wifi, and because the organizers want to minimize interference, they have banned all 802.11 communication (i.e., no wifi). However, buying 6 iPads with 3G/4G connectivity is pretty darned expensive especially with data plans. I'm really looking for a way to get the iPads to talk to the computer via bluetooth or USB if possible. I'm pretty sure I'd be able to get the iPads to talk to each other with the Game Kit and bluetooth, but is there any way I could trick a laptop to "think" it's an iOS device to make it connect via bluetooth? Or am I stuck buying a 7th iPad to act as the host?

LP0 ON FIRE
Jan 25, 2006

beep boop
Someone on the Cocos2D forum answered back with a suggestion that worked for the same "slow down" problem that worked for Cocos3D. In applicationDidBecomeActive, instead of calling resume on the director like [[CCDirector sharedDirector] resume];, call it like this with a selector:

[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(resumeGame:) userInfo:nil repeats:NO];

and make my own method that calls it in director:


-(void) resumeGame:(NSTimer *) sender {
[[CCDirector sharedDirector] resume];
}


Not sure why that fixes the bug, but it does.

I'm still having the transparency problem if anyone knows what could be up. I'm now suspecting it could have to do with setting CCTexture2D's DefaultAlphaPixelFormat like [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; ? Is it the wrong setting for Cocos2D having a transparent background? See my previous post for details.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
A couple weeks ago I built a game with cocos2d and I loved it. My first exposure to Obj C and Xcode too. All good things.

Only thing that kinda sucks is all the code examples out there talk about cocos 1.x, not the 2.0 I've been using. I've eventually figured out how to do everything I've needed though, so I guess that isn't actually a problem.

Doc Block
Apr 15, 2003
Fun Shoe

LP0 ON FIRE posted:

I'm still having the transparency problem if anyone knows what could be up. I'm now suspecting it could have to do with setting CCTexture2D's DefaultAlphaPixelFormat like [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; ? Is it the wrong setting for Cocos2D having a transparent background? See my previous post for details.

RGBA8888 means you're getting 32-bit textures with full alpha transparency support. This is what you want if you are looking for textures that have smooth gradients and smooth alpha transparency instead of just on/off transparency. It takes up the most memory, though.

It could be a bug in Cocos2D, it could be a bug in iOS, or it could just be weirdness resulting from the combination of the specific blending modes Cocos2D is using, your framebuffer's pixel format, and having UIKit stuff underneath. Newer versions of Cocos2D get along better with UIKit.

Doc Block fucked around with this message at 02:54 on May 23, 2012

duck monster
Dec 15, 2004

Carthag posted:

I get an exception in my code:

code:
2012-05-12 16:32:13.787 otest[33892:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[8]'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff93f8afc6 __exceptionPreprocess + 198
	1   libobjc.A.dylib                     0x00007fff969b6d5e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff93f33ce1 -[__NSPlaceholderArray initWithObjects:count:] + 113
	3   CoreFoundation                      0x00007fff93f49281 +[NSArray arrayWithObjects:count:] + 49
	4   CoreFoundation                      0x00007fff93f48e50 -[NSDictionary allValues] + 400
So I check out the dictionary in the debugger, and it has a key/value pair of (null) = (null);?!?

code:
(NSMutableDictionary *) $4 = 0x00007fcc6e2f3760 {
    census = ...;
    childInFamily = ...;
    sourceCitation = ...;
    birth = ...;
    noteReference = ...;
    death = ...;
    spouseInFamily = ...;
    christening = ...;
    (null) = (null);
}
Now how the hell did I manage to put that in? As far as I know that shouldn't be possible? The docs say that it'll raise an exception (setObject:forKey:) or attempt to remove the key/value pair (setValue:forKey:) so it can't be those... :psyduck:

You didn't somehow let it garbage collect it or something thats nulled it out?

Though gently caress knows why the key would be missing. Weird rear end thing.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I wrapped both read & write access to the dictionary in @synchronized() blocks and that seemed to take care of it (I was accessing the dictionary in some concurrent array & set enumerations, so presumably that was the cause. The mutable containers aren't threadsafe). It's been refactored away now though.

Under ARC, too, so no garbage collection.

duck monster
Dec 15, 2004

Carthag posted:

I wrapped both read & write access to the dictionary in @synchronized() blocks and that seemed to take care of it (I was accessing the dictionary in some concurrent array & set enumerations, so presumably that was the cause. The mutable containers aren't threadsafe). It's been refactored away now though.

Under ARC, too, so no garbage collection.

Concurrency is dark magic voodoo sometimes. Sounds like plain old memory corruption. Glad you solved it. :)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I am trying to put a Movie player on the screen centered horizontally (equal space left and right), that *stays* centered when I rotate the device. My thought process is: figure out where to put movie view, put it there, set auto-resizing masks to flexible left and right margins.

Objective-C code:
MPMoviePlayerController *aMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:
        [NSURL fileURLWithPath:url]];
self.moviePlayer = aMoviePlayer;
[_moviePlayer prepareToPlay];
CGFloat vidX = (currentOrientation == UIInterfaceOrientationPortrait || 
               currentOrientation == UIInterfaceOrientationPortraitUpsideDown) ? 
               VIDEO_PLAYER_XPOS_PORT :  // 143.0
               VIDEO_PLAYER_XPOS_LAND;  // 272.0
logger(@"putting video at X: %f", vidX);
_moviePlayer.view.frame = CGRectMake(vidX, VIDEO_PLAYER_YPOS, VIDEO_PLAYER_WIDTH, VIDEO_PLAYER_HEIGHT);
_moviePlayer.view.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin |
         UIViewAutoresizingFlexibleRightMargin | 
         UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:_moviePlayer.view];
logger(@"OH HAY I AM MOVIE PLAYER AND I AM AT X: %f", _moviePlayer.view.frame.origin.x);
Doing this puts the movie very close to the left edge of the parent view, despite both log statements giving the expected value. Removing the UIViewAutoresizingFlexibleLeftMargin from the auto resize mask puts the view where I expect it, but then does not center it on rotation.

Should I give up and just move the view manually in a rotation handler, or am I doing something stupid?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



btw can we put either of these on every page?

Ender.uNF posted:

Threads: The Great Heisenbug Simulator.

duck monster posted:

Concurrency is dark magic voodoo sometimes. Sounds like plain old memory corruption. Glad you solved it. :)

:tipshat:

dizzywhip
Dec 23, 2005

Is there a way to customize the appearance of an NSPopover? The popover's view doesn't reach all the way to the edges:



I'm trying to achieve an effect similar to the popovers in the GitHub app, with content extending all the way to the edges:



I suspect the answer is going to involve implementing an entire custom popover class from scratch, but maybe there's a way to just override the drawing of the standard popover.

duck monster
Dec 15, 2004

e: scratch that, macos not ios. Can you just do a plain old view and set it transparent or something? I havent really poked around the macos sdk yet.

dizzywhip
Dec 23, 2005

Well I can't use just a view because I need it to function like a popover and be overlaid on top of other views. I would need to somehow override the drawing of the popover itself or draw outside of the bounds of the popover's view (NSBezierPath's setClip didn't work).

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
GitHub for Mac uses Chameleon, so if you go the custom route, you can check out their implementation. I doubt it'll be worth outright lifting their classes but it might give you a head start.

If I was reimplementing it, I'd use an attached NSWindow. It's mostly boilerplate from there.

NoDamage
Dec 2, 2000
You could try out Matt Gemmell's MAAttachedWindow instead: http://mattgemmell.com/2007/10/03/maattachedwindow-nswindow-subclass/

It has the added benefit of pre-Lion compatibility (if you care about such things).

dizzywhip
Dec 23, 2005

I'm not thrilled about the idea of implementing a popover from scratch, and GitHub's appear's to be tightly coupled with the rest of the Chameleon UI stuff, so that one's not super useful unfortunately. I might use MAAttachedWindow, but first I'm going to try and modify the design of my popover to work with the bordered area. Thanks for the links.

duck monster
Dec 15, 2004

pokeyman posted:

GitHub for Mac uses Chameleon, so if you go the custom route, you can check out their implementation. I doubt it'll be worth outright lifting their classes but it might give you a head start.

If I was reimplementing it, I'd use an attached NSWindow. It's mostly boilerplate from there.

That looks loving awesome and it totally bookmarked now.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





I know Apps from the same developer can share certain permissions and capabilities, but if I create an AssetLibrary asset from one app, is it marked editable from another app (from the same developer)?

the talent deficit fucked around with this message at 04:35 on May 30, 2012

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

RGBA8888 means you're getting 32-bit textures with full alpha transparency support. This is what you want if you are looking for textures that have smooth gradients and smooth alpha transparency instead of just on/off transparency. It takes up the most memory, though.

It could be a bug in Cocos2D, it could be a bug in iOS, or it could just be weirdness resulting from the combination of the specific blending modes Cocos2D is using, your framebuffer's pixel format, and having UIKit stuff underneath. Newer versions of Cocos2D get along better with UIKit.

Thanks.. I'm hoping it's the combination of blending modes. I'm going to read more about different blending modes and experiment to see if I can get rid of the problem.

some kinda jackal
Feb 25, 2003

 
 
Gordon Cole let us know what you end up deciding about your popover situation because I've got a view that I'd like to display edge-to-edge in a popover as well.

Can't believe there isn't an option for that :(

dizzywhip
Dec 23, 2005

I gave up and decided to just deal with the border :( I just drew a 1px rounded border around the content area and treated the inside as if it were the edge of the popover. It doesn't look that good but I'd rather not deal with the hassle of using a completely custom popover right now.

If I had more time to spend on this, I'd take something like MAAttachedWindow and customize it to look how I need it. It'd be really annoying to emulate a bunch of standard behavior just for this one small customization though.

xgalaxy
Jan 27, 2004
i write code
I'm still fairly new at the whole thing but couldn't you manipulate the quartz layer size/position or will the popover container clip that?

some kinda jackal
Feb 25, 2003

 
 

Ah, fair enough.

I wonder if there is a way to deliver suggestions like this to Apple. It doesn't feel like something that ought to go into the Bug Reporter but I think that's actually exactly where it needs to be suggested.

lord funk
Feb 16, 2004

Martytoof posted:

Ah, fair enough.

I wonder if there is a way to deliver suggestions like this to Apple. It doesn't feel like something that ought to go into the Bug Reporter but I think that's actually exactly where it needs to be suggested.

To be honest, it's not really their design philosophy. Take the UIAlertView, which is basically impossible to modify. It takes a ton of work to roll your own, so it's a like setting a bar for developers: use our functional design, or you better know what you're doing if you make your own.

Not saying it's always the best way, but it's sometimes worth it. Like not really being able to easily set the color of rounded rect buttons. It would be the easiest thing to implement, but they must be leaving it out to prevent lovely lovely buttons everywhere.

dizzywhip
Dec 23, 2005

xgalaxy posted:

I'm still fairly new at the whole thing but couldn't you manipulate the quartz layer size/position or will the popover container clip that?

I haven't really ever worked at that low of a level, so perhaps, but the popover seems pretty strict about clipping. I tried using setClip and a layer-backed view (I believe core animation layers are usually allowed to draw outside of their containing view) and neither worked.

some kinda jackal
Feb 25, 2003

 
 
I might throw the question up on StackOverflow. That place has been pretty good for some obscure questions.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

the talent deficit posted:

I know Apps from the same developer can share certain permissions and capabilities, but if I create an AssetLibrary asset from one app, is it marked editable from another app (from the same developer)?

On a somewhat related question, there is a lot of old/outdated info out there about this but on iOS, is it possible to share files between two apps from the same developer without going through the UIDocumentInteraction? I am thinking no but wanted to check.

It makes me wonder how stuff like a free/paid version of an app manage to share data. I have that issue right now - sometimes users buy the IAP in the free version then move to the paid version, but the IAP obviously doesn't come along.

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
Today I was chasing around an iOS ARC circular reference issue that took forever to track down, most assuredly because I was using the wrong tools. This specific object is created after a login, held in one strong property, and discarded via self.object = nil on logout. The self.object = nil was being called on logout, but the object's dealloc was never running. A new login would spawn a duplicate object. Clearly something in the object was creating a circular reference that should be __weak. (It creates several other objects and sets itself as delegate.)

After assuring that my one strong reference was being set to nil, I went to the allocations instrument. Viewing details on the object showed the initial allocation and nothing else. I temporarily nilled the strong reference immediately below its initialization, and instruments showed the object being released (verified correct).

If memory serves, in a non-ARC environment, the allocations tool shows every retain and release, making it easy to track down these issues. Failing that, you can always override retain and release and throw in some break points. Neither of these seems to work in ARC.

The issue ended up being a delegate property that had been recently converted from non-ARC to ARC holding a strong reference, of course, but it took several hours to track down. The problem object was set in the leaking object's init, but the problem did not happen if I immediately released the object after returning from its initialization. I found it by commenting out pieces of the problem object until the dealloc was called correctly.

I ended up converting the rest of the project to ARC in a futile attempt to resolve the issue first, so I suppose that's a net benefit.

What tools or methods did I miss?

Toady
Jan 12, 2009

Martytoof posted:

I might throw the question up on StackOverflow. That place has been pretty good for some obscure questions.

You might also try the Cocoa-dev mailing list.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ManicJason posted:

After assuring that my one strong reference was being set to nil, I went to the allocations instrument.

There's a Leaks instrument that's designed exactly for this kind of bug.

Adbot
ADBOT LOVES YOU

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
I didn't see anything in leaks at a glance and didn't expect to since this was a circular reference, not a leak. The object never deallocating when I freed my one strong reference was the problem.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply