# [tex-live] xdvipdfmx says "** ERROR ** Capacity exceeded"

Daniel Rubin drubin at dimedis.de
Fri Feb 19 13:04:25 CET 2010

Jonathan Kew wrote:
> On 19 Feb 2010, at 08:47, Daniel Rubin wrote:
>
>> Somebody else suggested the issue might be related to nested boxes.  As
>> I do have quite a lot of those, I'm hopeful that this might be the right
>> track.  What do you think?
>
> As I suggested to you on the xetex list,

Yeah, I realised only a few minutes late that the XeTeX list would have
been more appropriate from the start.  Apologies.

> I'm pretty sure this is the root of the problem.
>
> A trivial testcase would be something like
>
>   \global\setbox0=\hbox{x}
>   \newcount\n
>   \loop \ifnum\n < 250
>     \global\setbox0=\hbox{\box0}
>     \repeat
>   \shipout\box0
>   \end
>
> which you can run with plain xetex. This works fine. But increase the loop limit to 260, and you'll get the DVI_STACK_DEPTH_MAX error.

Hang on, I think I misread your original comment.  Do you think the
problem arises from a nesting _depth_ of 256 boxes? Your previous
example, here it is:

>   \def\appendtohbox#1#2{\setbox#1{\box#1 #2}}
>   \setbox0=\hbox{}
>   \appendtohbox0{\box1}
>   \appendtohbox0{\box2}
>   \appendtohbox0{\box3}
>   \appendtohbox0{\box4}

I assumed that the boxes 1 through 4 were put into box 0, side by side,
so we'd end up with 4 boxes in one top-level box, with a nesting depth
of only 2.

> Recompiling xdvipdfmx with a larger constant will defer the problem, but a nesting level of over 250 boxes is suggestive of a poorly-implemented page layout structure that could almost certainly be simplified/optimized.

I definitely don't intend to have boxes nested as deep as 256 levels in
my documents, so the culprit really has to be in my LaTeX code.  (Coming
to think of it, more than 255 boxes inside one top-level box sounds
pretty insane, too.)

> (Note that if you do increase the driver stack to allow such complex pages, you could eventually hit a hard limit in the DVI format, and a problem in how TeX generates it. I think it's either 32K or 64K -- can't remember offhand if the relevant values are signed or unsigned 16-bit numbers. TeX itself doesn't detect the overflow, but the DVI output it creates will be incorrect.)

Of course there must be some limit.  I was hoping that it was just under
some crazy worst-case circumstance that I reached the 256-depth limit,
and would never even come close to, say, 512.  But if I really produced
some nesting that was that deep there definitely is an error that would
tear down any limit I could come up with.

So thanks again, now I know what I need to go hunting for.

Have fun
----Daniel