Stack Memory Requirements

Some of the platforms we support have only a few kilobytes reserved for stack memory on threads different than the main one. Since the layout is expected to be executed on one of those threads you may experience stack overflow crashes due to insufficient stack memory available. To resolve the issue you should reserve enough stack memory to allow Gameface to execute the layout.

Required stack space memory for layout

36kB + (1kB * DOM depth) when using OTF fonts

8kB + (1kB * DOM depth) when using only TTF fonts

Detailed explanation

Executing layout has an initial cost of 1kB of stack memory required to set up and run the box layout algorithm. The box layout algorithm is recursive and solves the tree from the deepest node out and each recursion costs about 1kB of stack memory. Leaf nodes are likely to be text nodes and in that case, an additional 7kB of stack memory is required to set up the run text layout algorithm. The text layout algorithm works in pair with the third-party library FreeType for reading fonts and getting the glyph data. FreeType is designed to use stack memory as temporary memory to avoid heap allocations and it uses a great deal of stack memory for some of its features. The OTF format parser/reader requires 28kB of stack memory. This cost can be avoided by using only TTF fonts. Have in mind that these calculations are made from the call to ExecuteWork(Layout) and you have to take into account any previously occupied stack memory until that call and any stack memory required for the external memory allocations.

You can easily check the maximum depth of any page by running the following script:

(function getMaxNestLevel() {
    var i = 1, sel = '* > *';
    while(document.querySelector(sel)) {
        sel += ' > *';
    return i;

An example of how much thread stack space is required for DOM depth of 15, stack memory occupied before ExecuteWork(Layout) of 10kB and stack memory needed for the external allocator of 2kB:

(36kB + (1kB * 15)) + 10kB + 2kB = 63kB

In case only TTF fonts are used:

(8kB + (1kB * 15)) + 10kB + 2kB = 35kB