views:

240

answers:

4

SOLVED: This has been solved following the assistance of many people. I'm now writing this, so that people with similar problems can benefit from it. In order for me to recreate this bug, I had to run the distribution build on my device. This was accomplished following MrMage's advice, which told me to change the certificate to the developer, and not the distribution. This allowed me recreate the error and debug it. The problem turned out to be that the compiler was ignoring all calls to set a CGSize's values. I was able to prevent this by setting the "Optimization Level" in the target preferences to "None", instead of "Fastest, Smallest".


Hello there,

I have a very peculiar in my application. A few days ago, my app got approved into the app store, but to my horror I soon discovered that there was a major bug in it. I went to my computer, but when a ran the code(both in the simulator and on the device), it all worked perfectly. I have tried everything: recompile and commit an update, clean all targets, reinstall the SDK, etc.

Here is a more detailed description of the problem. I have a detail table view in my application which loads some data from an online source. It displays a loading view while it downloads, and then reloads the tableview once the datasource is set. The table's cells contain UITextViews, which changes size to fit the text. When I run the app on the computer, or debugging on the device, the text is downloaded and displayed perfectly, but when I download from the App Store and launch it, it will only display text the first time, and then leave blank for the rest. I know the data gets downloaded because the texviews resize themselves to fit the text, they just don't display it.

Do anybody know what might be causing this error? How can I know whether my distribution build contains an error, which doesn't show up in the debug build?

Yours, BEN.

PS: I have compared the target settings for the debug and distribution builds. The only difference I see is "Optimization level" under "Code generation". I have tried to change this for the debug build, but it doesn't reveal the problem.


EDIT: I solved the problem by doing what MrMage suggested. It turns out that this code is indeed the cause of the error. When running in the debugger, the width and height properties of 's' are constantly zero, and I can't change this no matter what. I'm looking into why this happens.

- (void) setText:(NSString *)string 
{

CGSize s = [string sizeWithFont:textView.font constrainedToSize:CGSizeMake(290, FLT_MAX)];
s.height += kStaticSize;

//SizeWithFont is very unreliable so have to do some dirty tweaking
if (s.height > 100 && s.height <= 250)
    s.height += 20;
else if (s.height > 250 && s.height <= 500) 
    s.height += 40;
else if (s.height > 500 && s.height <= 800 )
    s.height += 50;
else if (s.height > 800 && s.height <= 1200)
    s.height += 60;
else if (s.height > 1200 && s.height <= 1700)
    s.height += 100;
else if (s.height > 1700) 
    s.height += 200;

s.width = 290;
CGRect r = textView.frame; 
r.size = s;
[textView setFrame:r];

[self.textView setText: string];
[self.textView setNeedsDisplay];

}
A: 

How have you changed your code since the update? (I hope you're using some form of version control) I don't think target settings would have much to do with it.

In the meantime I would remove it from the store if its that critical of an error. Then work on making the next release stable and extensively testing it.

(I don't think you need to use custom tableView cells to resize the text, I'm pretty sure the stock Apple ones do that automatically.)

JoePasq
I have made absolutely no changes to the source code, and I've published an update to make sure I hadn't. I have indeed also removed my application from sale, and that is really bugging me.As for extensively testing it, there is nothing I would rather do. My problem is the program is rock-solid in all my testing environments.
Benjamin Egelund-Müller
+2  A: 

Did you ever test an optimized build? The optimizer can do some really funky things (like rearrange your code), and this might cause problems if you have an uninitialized variable.

I'd also suggest running Clang (do a Build & Analyze).

David Dunham
Thank you for your suggestions. I tried running clang and it didn't find anything. I've also tried building the debug build with all the optimization options individually; didn't make a difference....
Benjamin Egelund-Müller
A: 

Under the heading of wild guessing.

I would look at any difference between you development environment and normal operational environment. For example, in my development environment, my iPhone defaults to my wifi for everything except phone calls. Since some network operations are time and bandwidth sensitive, it might be that operating over 3G/edge is the problem.

I am trying to think of what could cause the textviews to scale to hold text but not display the text. The textview can't scale to fit if it has nothing to fit. This suggest that either the text is composed of white spaces or that that the alpha of the text color is zero for some reason. Do you do anything setting the text color/font?

TechZen
I have posted the source code in my original post, as far as I can see, there is nothing.
Benjamin Egelund-Müller
+2  A: 

Did you try to just take your distribution build configuration and change its code signing options to iPhone developer, and then test that build on your device?

As far as I know, you can also upload binaries signed with a developer certificate by now. So you could take a working developer build and submit that one to Apple.

MrMage
That's it! It worked perfectly(or not perfectly, which was what I wanted it to do). When I do this and run on the device (still no problem in simulator), I get the error which I previously have not been able to replicate. I'll edit my first post to show this, and add some more information as to why this occurs.
Benjamin Egelund-Müller
Nevertheless, this is _very_ strange behavior. The compiler should _not_ optimize away changes to variables that you'll need later.
MrMage