Git Product home page Git Product logo

Comments (6)

seifertm avatar seifertm commented on June 12, 2024

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

from vectorgraphics2d.

olegs avatar olegs commented on June 12, 2024

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

from vectorgraphics2d.

seifertm avatar seifertm commented on June 12, 2024

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.

from vectorgraphics2d.

olegs avatar olegs commented on June 12, 2024

Yep, this is possible in our use case.

from vectorgraphics2d.

seifertm avatar seifertm commented on June 12, 2024

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.

from vectorgraphics2d.

olegs avatar olegs commented on June 12, 2024

@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!

from vectorgraphics2d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.