# Clash between ocgcolorlinks option of hyperref and patterns library of TikZ

I have stripped down to the following MWE after some experimentation. As it is, it works without any problems.

\documentclass{memoir}

\usepackage{tikz}
\usetikzlibrary{patterns}

\author{The author}
\title{Some title}

\begin{document}
\frontmatter
\maketitle
\listoffigures
\mainmatter
\chapter{first}
\section{first}
Some figure
\begin{figure}%
\centering
\begin{tikzpicture}
\draw[fill,pattern=north east lines,thick] (0,0) rectangle (5cm,2cm);
\end{tikzpicture}
\caption{Some caption}%
\label{fig:a1}%
\end{figure}
\end{document}


Notice the coloring and the weight of the font on LoF entries:

But when I change the location of the hyperref declaration to somewhere after TikZ and its library declaration, the whole figure environment just vanishes (but LoF still knows that it's there) also LoF entry loses its color(I guess!).

If I remove the patterns library dependence (fill=yellow or anything else) the second picture above is obtained and the TikZ picture is rendered correctly regardless of the declaring order. This suggests that the second image is the correct one and something fishy is going on either in the pattern library or ocgcolorlinks option. Does anyone know why? Or is it a bug?

I work with MikTeX 2.9, TikZ/PGF 2.10, hyperref6.83c

-
I couldn't replicate it here but in my original big file, the resulting PDF triggers a corrupted file error on Adobe Acrobat X on the pages where I have patterns in TikZ figures. Is it possible that ocg mechanism throws everything to another layer? I didn't test it but maybe if I print it, the story gets more mysterious. – percusse Sep 22 '12 at 23:56

Update: After a closer look I found that both packages overwrite the token register \pdfpageresources with deleting the previous contents. Of course there are problems, if the same keys are set by different packages. In this case however, TikZ sets /ColorSpace, /Pattern and /ExtGState, whereas hyperref puts key /Properties there. Therefore I will update hyperref to preserve the previous contents of \pdfpageresources. Then the example will work, if hyperref is loaded after pgf. The current situation is that either the TikZ's patterns or hyperrefs ocgcolorlinks are broken.
When I load hyperref version 6.83k with option ocgcolorlinks after loading tikz, I get a warning: Package hyperref Warning: The PDF version number could not be set, because some PDF objects are already written: 3 PDF objects The version should be set as early as possible: \pdfminorversion=5\relax. – Andrew Uzzell Oct 31 '12 at 10:38
@AndrewUzzell Just do thus. Put \pdfminorversion=5\relax at the beginning before \documentclass (or before the first PDF object is written). – Heiko Oberdiek Oct 31 '12 at 10:40