Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4 internal compiler error: bus error

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.

like image 266
Tom Avatar asked Mar 30 '11 23:03

Tom


3 Answers

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.

like image 73
Alex Avatar answered Nov 10 '22 08:11

Alex


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.

like image 45
Aaron Goselin Avatar answered Nov 10 '22 08:11

Aaron Goselin


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.

like image 1
CJ Teuben Avatar answered Nov 10 '22 10:11

CJ Teuben