Thursday, April 25, 2013

Announcing our new release - Coherent UI 1.2.1

Coherent UI in Planet Annihilation

First we would like to show some pre-alpha footage of Planetary Annihilation the devs from Uber Entertainment have put online. The footage looks great and it is going to be a terrific game, we can't wait to see more and play it. Oh, and by the way, the user interface is powered by Coherent UI.



New release


We have recently released Coherent UI 1.2.1. It has two major new features - handling of downloads and exporting .Net objects with their methods to JavaScript. Also we have re-designed our internal task scheduling routines and gained up to 30% performance improvement. That helped us to improve the on-demand views, which are now much faster.

Downloads Handling API

Coherent UI supports a full in-game browser and now using the SDK developers can add download file functionality. When the user clicks on a downloadable file the API provides a notification and the developer can handle the download. API also allows developers to make direct file download request, with progress notification and multiple protocols support.

This opens a myriad of new possibilities like using Coherent UI for your game's launcher or updater - achieving both a visually stunning front-end and easy to code download/update functionality, without the need to handle the transfer yourself or to integrate other third-party libraries.

File download also enables developers to integrate seamlessly advanced social features like users sharing photos, videos or other content. Also game asset streaming - downloading resources in run-time becomes a piece of cake to implement. The potential usages of the feature are countless and the combo UI/browser/file downloads makes Coherent UI much more useful set of tools for many more tasks on top of  user interface implementation.

.Net/Unity3D Method binding

Since its very first release Coherent UI already supported binding and executing of arbitrary .Net delegates by JavaScript. However it required explicit registration of each delegate via the View.BindCall and View.RegisterForEvent methods, which made it somewhat time-consuming and prone to typos. So we've added a new feature, that automatically exports .Net object with all of its methods to the browser JavaScript. This means you can call any .Net method on any object writing only a single line of code.

How it works?

You just wrap the object and send it to JavaScript as an argument to an event or as a result of an engine.call handler and that's it - you can call every method of the object from JavaScript.

Here is how we use the Options instance in JavaScript:

Note that for every method of the .Net object that has return value, calling the JavaScript method returns a promise for this result.


This cool feature is available only for .Net and Unity3D for now, but we are going to add it to the C++ API too.

To give Coherent UI 1.2.1 a try download it from our website.

Tuesday, April 16, 2013

Objective-C++ ARC gotchas

Lately I had to mix C++ and Objective-C pretty heavily (it's called Objective-C++ apparently). What I usually need is having Obj-C objects inside C++ ones, which with "Automatic Reference Counting"(ARC) should work out-of-the-box. It actually does - except when it doesn't!

In essence what the compiler probably does is just add 'retain' & 'release' calls in the proper places (constructors, destructors etc.). It is smart enough to recognize pointers to ARC objects and treat them as non-POD.

This is actually very cool and simplifies the interaction a lot. Alas there are some problems when you try to do some more 'exotic' stuff.

A pretty standard C++ way to use your own memory management routines is to allocate some memory with your custom allocator and then use placement new to construct an object in the fresh memory. Destruction goes the other way around - call the destructor explicitly and deallocate your memory.

In the following code, as you might expect, 'dealloc' is called as soon as the C++ object is destroyed - so no leak happens:

However if you uncomment the 'virtual' keyword and hence make the hierarchy virtual the 'dealloc' method will not be called. The compiler in this case does not create the non-trivial destructor required! If you substitute the manual memory management with the delete operator then the destructor is synthesized and 'dealloc' gets called. The behavior is also prevented if your class is non-POD in C++ terms.

Not having a virtual destructor in a virtual hierarchy is arguably very bad, however breaking the ARC promise is even worse. I admit that stumbling upon this issue is not very easy because it requires a lot of things to happen but still the leaking references it introduces are serious enough to prompt me to write about it.

I haven't looked at clang's source about this issue and I can't find a rationale behind it in the docs so I think it's an oversight and can only speculate why it happens. The version of the compiler that I currently work and saw the problem is: "Apple clang version 4.1 (tags/Apple/clang-421.11.66)".

All that said, if you follow the basic C++ guidelines of having virtual destructors in your polymorphic hierarchies you should be fine when you try to mix C++ and Objective-C.