App runs fine in simulator, black screen on device

Hi All,

Have been having a problem for the past week or so. My app runs as expected in the simulator, but when I try to send it to the phone or iPad, I get only a black screen. xCode doesn't report any problems. Juce Demo appears to be fine with the latest updates. 

Any suggestions of what I might have screwed up or where to look? This did start happening after I pulled the latest Juce last week, but since the demo is fine, I'm scratching my head. 

Nick

*crickets*  ... yeah I guess that was a pretty open ended call for help :)

the eventual solution I found to this problem was to replace a HighResolutionTimer I was using with a regular Timer. For whatever reason the Juce hi res timer is not working correctly on iOS on devices (works fine in simulator). I tried using it in another spot in my app, and it resulted in the timer not running, but otherwise no problems like the black screen mentioned before. 

For funsies I replaced the timer in the Juce Demo timers and events page with a high res timer. The timer will run in the simulator but not on a device. 

n

 

Well, there's a bunch of android-specific code in the high-res timer, so I'm guessing it must have worked correctly when I wrote it! It'll be quite time-consuming to debug this, and I don't have time to look at it right now, but will do so when I get chance.

ok, thanks Jules.

Ok, just tested HighResolutionTimer on my android device and it runs just fine.

You realise that the callback happens in a background thread, right? You can't just replace a regular Timer with a high res one unless your callback code is thread-safe..

you do realize I was talking about iOS not android right? 

ah.. no, for some reason I had "android" in my head!

But iOS uses the same code as OSX. Are you sure this isn't a threading issue like I suggested above?

well I think what I'm doing is thread safe within the callback. It appears that the callback never gets called at all actually. Again, fine in the simulator, but on the iPad or iPhone it doesn't work. 

Is there some other way I might be misusing the timer? Let's take the Juce Demo as an example. If you replace the timer in the timers and messages page with a high res timer, should it run? 

n

If you replace the timer in the timers and messages page with a high res timer, should it run? 

No, it shouldn't! Not if it tries to do any GUI work in the callback - that will cause all kinds of trouble on a background thread.

ok, bad example. all i really need to do with the callback is send a message. If all I do in the callback is write hello world to the console that doesn’t work for me on an iOS device, but it works elsewhere.

Seems to work fine for me (in the iOS simulator)

works great for me too ... in the simulator! Try it on a device, it doesn't work. 

Ah, my iPhone died and I don't have a physical device to try any more. Any clues about where it fails?

oh no! If I had a spare I'd send it your way.

The problems I've seen might be related to starting or stopping the timer. The black screen at launch happened when I was stopping the timer (stupidly) before it was even started. But regardless, the timer callback is not ever getting called after the timer starts as far as I can see. 

If there's any specific test you want me to try here just let me know. 

Well it's only a very small piece of code - in juce_posix_SharedCode.h, line 1220. The code looks completely fine to me and is the same on OSX and the simulator, so I've no idea what's going on. The thing to do would just be to see what happens in that Clock class, and look for anything strange.

I have the same problem here. I'm using the highRes timer for a MIDI clock generator.

Jules, there is a easy solution for you. Just use the android code for iOS -> works!

Line 1220... juce_posix_SharedCode.h

EDIT:

Change from

       #if JUCE_MAC || JUCE_IOS
        Clock (double millis) noexcept
        {
            mach_timebase_info_data_t timebase;
            (void) mach_timebase_info (&timebase);
            delta = (((uint64_t) (millis * 1000000.0)) * timebase.numer) / timebase.denom;
            time = mach_absolute_time();
        }

        void wait() noexcept
        {
            time += delta;
            mach_wait_until (time);
        }

        uint64_t time, delta;

       #elif JUCE_ANDROID

to

#if JUCE_MAC

...

#elif JUCE_ANDROID || JUCE_IOS

Works in simulator and pyhs dev.

The android code performance is bad and the iOS timer works, but is very very to slow!

I have changed the millis multiplier from 1000000.0 to 575.0 and then it works on the phys device. That's going on?
(I don't know the right multiplyer, but about 575 looks ok and my clock is working well)

I have tested this on iPad2. I have also an iPad3 here but not tested jet. Can anybody test this on iPhone and iPad4??

        #if JUCE_MAC || JUCE_IOS
        Clock (double millis) noexcept
        {
            mach_timebase_info_data_t timebase;
            (void) mach_timebase_info (&timebase);
            delta = (((uint64_t) (millis * 575.0)) * timebase.numer) / timebase.denom; // 1000000
            time = mach_absolute_time();
        }

Hmmm!?!

Goddammit.. Looks like I got the numerator and denominator the wrong way round.

On OSX it still works fine because both values are always 1.. Presumably swapping those two variables fixes it in your app?

Yes, that's the problem. Works fine in Simulator and on the phys device if the var is swapped.