Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE from SVGGraphics2D#getBytes #42

Closed
olegs opened this issue Jun 5, 2016 · 6 comments
Closed

NPE from SVGGraphics2D#getBytes #42

olegs opened this issue Jun 5, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@olegs
Copy link

olegs commented Jun 5, 2016

Happened with 0.11 version released recently.

java.lang.NullPointerException
    at java.util.LinkedList$ListItr.next(LinkedList.java:893)
    at de.erichseifert.vectorgraphics2d.intermediate.filters.Filter.a(SourceFile:51)
    at de.erichseifert.vectorgraphics2d.intermediate.filters.Filter.hasNext(SourceFile:45)
    at de.erichseifert.vectorgraphics2d.intermediate.filters.Filter.a(SourceFile:50)
    at de.erichseifert.vectorgraphics2d.intermediate.filters.Filter.hasNext(SourceFile:45)
    at de.erichseifert.vectorgraphics2d.intermediate.filters.GroupingFilter.hasNext(SourceFile:40)
    at de.erichseifert.vectorgraphics2d.svg.SVGProcessor.process(SourceFile:36)
    at de.erichseifert.vectorgraphics2d.ProcessingPipeline.writeTo(SourceFile:54)
    at de.erichseifert.vectorgraphics2d.ProcessingPipeline.getBytes(SourceFile:61)
@olegs olegs mentioned this issue Jun 5, 2016
@seifertm
Copy link
Collaborator

seifertm commented Jun 6, 2016

Are you using any form of multi-threading when this exception occurs?

@seifertm seifertm added the bug label Jun 6, 2016
@seifertm seifertm added this to the 0.12 milestone Jun 6, 2016
@olegs
Copy link
Author

olegs commented Jun 6, 2016

Yep, we have multithreading as following:
Create single SVGGraphics2D object, create multiple subgraphics (SVGGraphics2D#create) and paint in parallel.

@seifertm
Copy link
Collaborator

seifertm commented Jun 6, 2016

As far as I can tell, your approach should work.

Do you also call SVGGraphics2D.getBytes() in parallel?

VG2D was only tested with a single thread. I will try to help, but I don't know how well the current design of VG2D fits for multi-threaded use. I have do investigate a bit further on this.

@seifertm seifertm self-assigned this Jun 6, 2016
@olegs
Copy link
Author

olegs commented Jun 8, 2016

Yep, this is possible in our use case.

@seifertm
Copy link
Collaborator

Alright I did some investigation on this issue and found two major problems when using VG2D from multiple threads:

  1. The implementations of VectorGraphics2D, such as SVGGraphics2D translate the method calls into an intermediate representation. This representation consists of Command objects (e. g. TranslateCommand or DrawShapeCommand). The commands are not self-contained, which means that a DrawShapeCommand for example behaves differently depending on the current graphics state (e.g. Color or Stroke). Therefore, when multiple threads emit commands, the result is most likely garbled. This problem can be fixed by adding state information to the commands.
  2. The second problem is that all SVGGraphics2D objects created with create() share a common command list. When getBytes() is called in parallel, each threads processes commands from the same command list, which again causes commands like DrawShapeCommand to be called in the wrong graphics state. The NPE occurred, due to the same reason: One thread checked if there are commands left to process and enters an if-clause, but at the time he entered, another thread ate the remaining commands away.

Conclusion
Multi-threaded use of VG2D is currently not possible. I hate to let you down on this, @eseifert and I think that other matters are more pressing, such as changes to the overall design (see some of the other issues) to get a (more) stable API. I am afraid that you have to wait a bit longer for multi-threading to be supported with VG2D.

@olegs
Copy link
Author

olegs commented Jun 12, 2016

@seifertm Thanks a lot for the investigation and such a comprehensive answer, I understand, that switching to self-contained command system is quite a efforts and time consuming procedure. Probably separate feature request for multithreading access should be created? Anyway, well done, keep it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants