This is a proposed fix that removes any relationship with annotations and ruler because it looks this code was obsolete.
The code is still used, applying this patch means rules aren't saved for reuse anymore.
This is easy to test, add some rulers, save the file and reload.
Using grease pencil for rulers is a bit weak, so these could be moved into their own data-structures.
@Campbell Barton (campbellbarton) and is it GPencil datablock the place to save this? IMHO it looks weird use this..I know is a trick, but not the most elegant solution. If we add more things to annotations to support texts and other functionalities, we will have all the time this hack, and in the future this is only a source of problems.
Maybe the right place would be to add a listbase to Scene struct to save this data and split rulers from Annotations and GPencil. If all agree, I could try to do it.
Agree it's strange, it was a quick way to rules as store an arbitrary number of 2-3 point lines.
I wanted to avoid some overhead, consider having to add DNA/RNA, along with RNA functions to add/remove rulers.
Although we could just have DNA and not worry about RNA access, this is the kind of thing people might eventually want a Python API for.