letsfindaway / OpenBoard

I'm using this fork to contribute features and fixes to the upstream project. In order to create good pull requests, I'm rebasing my feature branches, squashing and reordering commits, etc. If you fork this repository be aware that my development branches may rewrite history without prior notice.
http://openboard.ch/
GNU General Public License v3.0
9 stars 0 forks source link

Improve scene handling #172

Closed letsfindaway closed 2 weeks ago

letsfindaway commented 5 months ago

This issue collects several other issues related to scene management, tries to provide a common overview and propose steps for solving. The issues are:

The effects for the user are

Reasons for these issues are

Steps for addressing these issues

The following proposes a step-wise approach to solve these interrelated issues.

letsfindaway commented 4 months ago

Note: There is one BIG problem with asynchronous loading:

All QGraphicsItem share a global object for storing data. This is a QHash<const QGraphicsItem *, QMap<int, QVariant> > data which stores the data for all items globally. Access to this hash is not protected against concurrent access from several threads.

As building a scene involves creating many items, where each item uses this map, we cannot safely do this on any other thread than the main application thread. This problem is completely independent of the thread affinity of objects and cannot be solved by the application.

The only possibility I see is to do loading on the main thread, but to cut it into small pieces, which are executed whenever the main thread is idle. Let me say, if the UBSvgSubsetAdaptor would have a function which reads data for a single item and creates that item, and then returns, we could call this function when the main thread has nothing else to do. Such a programming pattern requires that all context of loading is held in a variable which can be passed to this function. Let's see how big this context is! Best case it is only the XML reader and the scene.

letsfindaway commented 4 months ago

See https://github.com/OpenBoard-org/OpenBoard/pull/941 for my PR to address this issue.

Actually the context needed to load a file in small steps is the UBSvgSubsetReader if we move three local variables to member variables.