Xcode 4.0.1 has started giving me an internal compiler error. It just says "Bus error". It occurs at the bottom of one of my .m files, which is now almost 4000 lines long.
I've looked at this question, but I'm not making that mistake, and when it comes up I can usually fix it by adding some random lines of code somewhere. When it first cropped up, I tracked it down to where I was setting the frame of a view in a bunch of new code:
view.frame = CGRectMake(otherView.frame.origin.x, 0, otherView2.frame.size.width, 40);
If I replaced the otherView and otherView2 references with hardcoded values, the problem went away. Or if I simply put int x = 0;
above the offending line, it went away.
I've also looked at this question, but it doesn't have a clear answer. It doesn't seem to be any individual line of code; it just comes up seemingly randomly. And Google doesn't have any clear solution that I could find.
I've tried with all the possible compilers for the project (GCC 4.2, LLVM GCC 4.2, and LLVM Compiler 2.0, and they all have the problem. I have the Static Analyzer set to run every build, and turning it off doesn't help. This question seems to indicate it's a bug in the compiler. Am I just stuck? Is there a workaround?
EDIT: Another example: It happened again and I tracked it down to:
[headerView centerViewVertically:milesLabel pixelsFromRight:pointLabel.frame.size.width + 20];
I changed it to:
int x = pointLabel.frame.size.width;
[headerView centerViewVertically:milesLabel pixelsFromRight:x + 20];
And it worked again.
I hit this error and it turns out the mistake was mine, caused basically by a type-o, or more accurately a paste-o.
I was creating two labels and adding them to the subview. The code went essentially like this.
UILabel *pointsLabel = [[UILabel alloc] initWithFrame:ptsFrame];
...
[self addSubview:pointsLabel];
[pointsLabel release];
UILabel *typeLabel = [[UILabel alloc] initWithFrame:typeFrame];
...
[self addSubview:pointsLabel];
[typeLabel release];
Notice in the second addSubview
I added the pointsLabel
again even though I had already released it (and really meant to add the typeLabel
). I would expect this to cause a runtime error as well but for whatever reason it caused the Bus Error describe above. Something to look for.
I just had this happen (not for the first time). I still haven't figured out exactly what is causing the problem but it will compile for the simulator, but not for the device. Moving my [[array alloc] init] out of my init method and into a separate setup method fixed the problem.
Maybe I'm allocating too much memory in too short a period or something? That seems unlikely however since there are several [[array alloc] init] array setups being done before and after the one I was trying to add in. Everything was being done absolutely identical to how the other arrays were being done so why it was a problem this time is something I don't yet understand.
I also got this error, only when compiling on device, after xcode preformed a modernize of my code. I switched the compiler to Apple LLVM 2.1 in both the project and the targets build settings and ran again. This picked up some stray ; in the project and the error bus error went away.
Did you deallocate any of the objects like otherView, Im pretty sure that produces a bus error in xcode.
Really looks like a compiler bug to me.
I got the same problem (Xcode 4.0.2; LLVM GCC 4.2). In a view controller's viewDidLoad I had a line:
self.title = @"Enter your details";
I didn't need this line anymore so I removed it and subsequent builds failed with "internal compiler error: Bus error". If instead of removing the line I changed it to:
self.title = nil;
the build compiled fine.
The detailed build log contained:
MyViewController.m:316: internal compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for instructions.
{standard input}:0:End-of-File not at end of a line
{standard input}:1704:End-of-File not at end of a line
{standard input}:unknown:Partial line at end of file ignored
{standard input}:1695:non-relocatable subtraction expression, "L_OBJC_CLASSLIST_REFERENCES_$_6" minus "LPC11_18"
{standard input}:1695:symbol: "L_OBJC_CLASSLIST_REFERENCES_$_6" can't be undefined in a subtraction expression
{standard input}:1692:non-relocatable subtraction expression, "L_OBJC_SELECTOR_REFERENCES_36" minus "LPC11_17"
{standard input}:1692:symbol: "L_OBJC_SELECTOR_REFERENCES_36" can't be undefined in a subtraction expression
[... any many more lines like this ...]
I got the same error by putting the next line of code:
tempButton.titleLabel.adjustsFontSizeToFitWidth = YES;
Doubling the same line of code it did not gave an error:
tempButton.titleLabel.adjustsFontSizeToFitWidth = YES;
tempButton.titleLabel.adjustsFontSizeToFitWidth = YES;
I encountered this problem in a project, but only when compiling for a device. When I built for the simulator it worked fine.
I was able to work around the issue by just changing my compiler from "LLVM GCC 4.2" to "LLVM Compiler 2.0" in the project's build settings.
I have to think that this is a compiler bug. It shouldn't be the case that syntactically valid yet semantically buggy code will cause the compiler to error out. The compiler does not execute the code, it just compiles it. So it shouldn't matter if you've got logic or memory management errors in there, the compiler doesn't care about those kinds of things.
Do you use any deprecated function?
I remove all calls to deprecated function and works!