Problem
The problem with current line art object loading code is that it iterates through the scene to access objects, which is unsafe during evaluation because the original data could be freed/replaced by depsgraph.
What this patch does
This fix is more or less a copy pasta from the physics relation cache code, does work correctly for regular objects and instanced collection, and I used duplilist when loading objects "from cached relations", so they will all load correctly.
Potential problem: duplilist could access some instances that is set as lineart exclude, in which case their relations are not added. Not sure the best way to get around this problem...
Update:
Sergey actually did say that we might need a "thread-safe" iterator during depsgraph evaluation. I'm not sure how it's gonna be implemented, should I personally go inside and try to mess around DG code or do I wait a bit?
The thing about is the old iterator code is 1) not actually crashing although it's technically unsafe, no crash reports is related to that part since line art has become a gp modifier. 2) I haven't had any crashes either (although rarely I could have one or two leaked memory blocks?) 3) It actually can handle instanced objects like particles stuff. So I'm thinking if this depsgraph problem is not very high priority in line art scope, can I revert back to using the old FOREACH_OBJECT_BEGIN thing? This patch is even not very usable (nor am I sure my method here is correct because apparently sometimes it crashes and the reference object pointer thing it gives line art is almost always wrong...?)