2

Hey idk if I am doing something wrong or if I should file a bug report for this.

I initiate UI elements to my main viewcontroller like the following:

    knob[7] =[[UIImageView alloc] initWithFrame:CGRectMake(a, b, c, d)];

    knobS[7]   =[[knobBand alloc] initWithFrame:CGRectMake(a, b, c, d)];

    knob[8] =[[UIImageView alloc] initWithFrame:CGRectMake(a, b, c, d)];

Then I do

    [self.view addSubview:knobS[7]];

    [knob[7] setImage:[UIImage imageNamed:@"knob"]];
    [knob[8] setImage:[UIImage imageNamed:@"knob"]];
    [self.view addSubview:knob[7]];
    [self.view addSubview:knob[8]];

If I put the [self.view addSubview:knobS[7]]; below the other 4 lines, the knob[7] and knob[8] will not show up at all, although they are the same size and only knob[7] is covered by knobS[7]. I thought this is some programming mistake so I didn't investigate this any further because putting said line above the 4 lines worked - until I built the project the third time and this is where it's getting weird:

Now, whenever I build, build&clean, clean&build, ... the project, one of these 3 things happen:

  1. Only knobS[7] is showing
  2. All 3 UI elements are showing
  3. the project builds but when launching it throws EXC_BAD_ACCESS at the setImage: line

And the amount of occurrences is pretty accurately summed up by the order; 1. is happening 60% of the times, 2. 30% and case 3 is happening in 1 out of 10 cases.

I tried rebooting and there isn't a single line of code grabbing the current time or a random value which might affect the outcome of the code. Even after hitting CMD+R twice within 10 sec without changing ANY code I get 2 different results.

Is there any other form of cleaning/building a project which might help here?

EDIT: This behavior is somehow not reproducible in Xcode 7, it's only 6 that causes the problems.

user2875404
  • 3,048
  • 3
  • 25
  • 47

2 Answers2

0

If I put the [self.view addSubview:knobS[7]]; below the other 4 lines, the knob[7] and knob[8] will not show up at all

You're creating three controls that are all the same size. Whichever one is added last will be on top. You may or may not be able to see the others, depending on how the one on top draws itself, whether the background is opaque, etc.

Now, whenever I build, build&clean, clean&build, ... the project, one of these 3 things happen:

Sounds like you've got a bad pointer and perhaps some other errors. If you use an invalid pointer, your app might throw an exception or it might not, depending on whether the pointer happens to point to a valid object. These kinds of problems have a very non-deterministic feel to them because they're very sensitive to tiny changes: where in memory the object was allocated in the first place, when it gets deallocated, whether anything else gets allocated using the same memory, etc.

I tried rebooting and there isn't a single line of code grabbing the current time or a random value which might affect the outcome of the code.

Doesn't matter -- you really can't expect the system to be in exactly the same state between one run of your app and the next.

Is there any other form of cleaning/building a project which might help here?

There's nothing wrong with how you're building the project, and it probably doesn't need to be cleaned either. To help find the problem, enable NSZombies, which will make your pointers to deallocated objects point instead to a small object that will trigger an exception when you try to use the pointer. That should make the problem more obvious and more reproducible.

Community
  • 1
  • 1
Caleb
  • 124,013
  • 19
  • 183
  • 272
0

enter image description hereGo to Xcode settings --> General --> Issues

Uncheck the "Show live issues". This solved the issue for me

Vamsy
  • 74
  • 7
  • But doing this eliminates one of the most useful features of Xcode. Personally I much prefer knowing about issues immediately rather than waiting until the next build. – HangarRash May 25 '23 at 20:02