Hello there!
I'm using a QThread to load approximately 100 MB of motion capture data. The reason why I use a thread is that it takes some time to load and process the data and when the program is started, I want to be able to watch the data in a 3D environment right away from the start and not wait until all the data is loaded. I have observed a problem several times and I believe it must be a thread related issue. Basically, some frames of the data, which is loaded into a QList, seem to be messed up sometimes. But here is a more detailed explanation.
So, the loader thread reads the data from a file line by line, writes each line in a struct and appends the struct to a QList like this:
QList<DataStruct> data;
struct.handX = line[0];
struct.handY = line[1];
...
data << struct;
QList<DataStruct> data;
struct.handX = line[0];
struct.handY = line[1];
...
data << struct;
To copy to clipboard, switch view to plain text mode
The 3D visualization object accesses directly the data QList of the file loader thread / object even during the time the data is loaded. When displaying the frames on the screen, I check if data.size() is larger than the frame I want to display and if this is true, I assume the frame is readily loaded.
if (frameIndex + 1 < loader.data.size() - 1)
{
frameIndex++;
displayFrame(loader.data[frameIndex]);
}
if (frameIndex + 1 < loader.data.size() - 1)
{
frameIndex++;
displayFrame(loader.data[frameIndex]);
}
To copy to clipboard, switch view to plain text mode
This works great aside from the following effect. Sometimes I would encounter a frame which is severely out of place, as if the order of the frames in the QList wasn't right. I can rewind and look at the same spot again and even after the loader thread has finished loading, the same spot stays screwed up during the entire runtime of the program. I checked if there is an error in the data file at this spot and it looks clean. Also if I quit and reload the program, there is no problem with the same frame anymore, but the problem might occur at a different frame that was ok before. So I think it must be a thread related issue, but I don't understand why.
First of all, I check the size() of the QList, so I never access a QList index that hasn't been already loaded with a frame. And second, I can understand that it would be an issue if I try to read a frame at the same time when it's just being written by the loader thread, but when I rewind and look at the same QList index later, then it should be clean because the writing has already been completed. And it is of course impossible to reliably reproduce, so I don't even know how to approach this problem. Any ideas?
Thanks
Cruz
Bookmarks