Dictation (Siri) keyboard crash

Hello,

Wondering if any devs have run into a problem with iOS9 and build setting Graphics API set to OpenGL 2.0.

This results on a crash exception in the UnityAppController+Rendering script. This is running any version of unity 4.6 at the moment. Even tried the latest 4.6.8p3 beta update.

I opened an issue (https://fogbugz.unity3d.com/default.asp?730560_0769rgl0vk19ojco) with an empty bare project. Unity has fixed it for previous versions, but looks like a big change was made recently in the UnityAppController script.

Setting the Graphics API to Automatic and it doesn’t crash. I also can get around it by pausing the unity engine when keyboard is up, but that’s an ugly hacky fix.

yeah we found this bug: essentially siri is using gles context so essentially we’ve been missing some “please make our context current”. I am not sure if it was backported to 4.x (well, it wasnt as you see crashes) but the fix is entirely in trampoline so if you are fine with editing objc code i can give you some instructions right away

Yeah we have worked with ObjC often, so I’m somewhat comfortable with ObjC. Any help with this would be great as we want to release within the next week or so.

ok, so essentially the gist of it is that siri wants gl context and to be rendered alongside your view. So you need to play nice with it.
first of all in Classes/Unity/EAGLContextHelper.h
add forward declaration for

struct UnityDisplaySurfaceBase;

and then inside class EAGLContextSetCurrentAutoRestore add constructor:

EAGLContextSetCurrentAutoRestore(UnityDisplaySurfaceBase* surface);

so it looks like that

struct UnityDisplaySurfaceBase;
<...>
class
EAGLContextSetCurrentAutoRestore
{
public:
   EAGLContext* old;
   EAGLContext* cur;

   EAGLContextSetCurrentAutoRestore(EAGLContext* cur);
   EAGLContextSetCurrentAutoRestore(UnityDisplaySurfaceBase* surface);
   ~EAGLContextSetCurrentAutoRestore();
};

then in Classes/Unity/EAGLContextHelper.mm
add

#include "UnityRendering.h"

and implementation for new ctor

EAGLContextSetCurrentAutoRestore::EAGLContextSetCurrentAutoRestore(UnityDisplaySurfaceBase* surface)
  : old(surface->api == apiMetal ? nil : [EAGLContext currentContext]),
   cur(surface->api == apiMetal ? nil : ((UnityDisplaySurfaceGLES*)surface)->context)
{
   if (old != cur)
     [EAGLContext setCurrentContext:cur];
}

Afterwards you just need to go to Classes/UnityAppController+Rendering.mm and add

EAGLContextSetCurrentAutoRestore autorestore(GetMainDisplaySurface());

to

static void UnityRepaintImpl(bool forced)

so it looks like this

static void UnityRepaintImpl(bool forced)
{
   @autoreleasepool
   {
     EAGLContextSetCurrentAutoRestore autorestore(GetMainDisplaySurface());

     Profiler_FrameStart();
<...>

again, i cannot even build 4.x now, so you need to use c/objc knowledge to fix possible compilation errors (if i forgot to mention some incudes or smth)

Hope that helps

That worked perfectly. Just as you wrote it. Thanks for the detailed break down.

We don’t append builds so we have a python/perl system that just searches and adds whatever fixes or updates so this is pretty straightforward to add.

Thank you very much.

We’re having a similar issue with Unity 5.2.1 and iOS 9; we checked the Xcode files and the changes mentioned above seem to already be made in Unity 5.2.1. Is there another reason this may be happening? Has anyone else had this problem with Unity 5.2.1?

Hello again, so we updated to unity 5.2.3 and we’re seeing the same issue. Might be what jareds is seeing. The exception is occurring in a slightly different place though. I don’t see any issue trackers for this problem.

Attached image.

Have you submitted a bug report with a reproduction project attached? If not, please do this and tell the bug number in this thread. Thanks