Forum Bugs

Mercury runtime: caught segmentation violation

phpuser
I got the following error when I tried to convert the PHP manual [https://php.net/get/php_manual_en.html.gz/from/a/mirror] from HTML to PDF:

*** Mercury runtime: caught segmentation violation ***
This may have been caused by a stack overflow, due to unbounded recursion.
exiting from signal handler

I guess my system ran out of memory (2 GB RAM). But how do I know how much memory is required? Or is there a way you can cut down the memory usage by the application itself?
mikeday
I tried it and it takes about 3.3 GB, so you will probably need to use a 64-bit version of Prince on a machine with > 4GB of RAM.

The resulting PDF file is over 14,000 pages long. :)
phpuser
I managed to make it work on a machine with 4 GB RAM. However, there is a problem with the output: in many places, the PDF has text chopped off rather than wrapped to the next line. For example, see the following subsection:

Installation on Unix systems > Sun, iPlanet and Netscape servers on Sun Solaris > Configuration Instructions for Sun/iPlanet/Netscape

Instruction 2 of this subsection contains configuration lines starting with "Init fn=..." and these lines spill over the right side of the page and are chopped off.

I tried to accommodate such lines by using --page-size=A3 but even that isn't enough. In any case, this behavior shouldn't happen at all.
mikeday
Try adding this CSS rule:
pre { white-space: pre-wrap }
phpuser
That doesn't work when a line contains a sequence of too many "unwrappable" characters. For example, see: Installation on Windows systems > Manual PHP Installation on Windows > Choose Web Server > Example #1.

If Prince cannot handle such cases on its own, it should at least generate warnings giving details about all the places in the PDF where content has overflowed the page. The way it is, even with verbose debug logging, there are no messages that can help to locate these places.
mikeday
You can allow breaking words:
pre {
    white-space: pre-wrap;
    overflow-wrap: break-word
}

You might get slightly nicer results by adding a zero-width space after commas:
pre {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    prince-text-replace: ',' ',\200b'
}

Reducing the font-size for pre tags would also help; monospace fonts take up more space!

It would be convenient to have better warnings for overflowing text, hopefully we can do this in the future.
phpuser
"prince-text-replace" works but I prefer a more general solution. So I used "word-break: break-all" instead. The output appears to be as intended but I did get the following warning:

GC Warning: Failed to grow mark stack to 524288 frames

Could this warning mean there is a problem with the output at some as-yet-unseen place?
mikeday
We will investigate this.