I continued working on my part in the project this week, that is, the JointJS schematic editor. First I finished some final touches on the save/load feature I did last week, then I worked on the other two tasks that i was assigned to. These were parsing the JSON file received from the the load operation, and creating a new project from within a Wresource “handlerequest()” method.
To do the first task, I was asked to use the boost property tree library. Thus, the first thing I did was to understand how Json files are constructed, and then I spent some time going through the property tree library. JSON files are very simple and it didn’t take me much time to understand. Also, exploring the property tree library was very straight forward and didn’t take time to understand how to parse a JSON file. I then tried a simple application “without Witty” and everything worked as expected. I was then ready to start working on the project. To my surprise, the server always crashed when using the property tree JSON parser! Once I call the function
the server would crash with an error std::bad_alloc. I tried this simple example here, but it also caused the server to crash! I spent the rest of the day searching the internet for solution, but without any success. Though I know that error would occur when a program is taking too much memory, I did not know what I can do to solve this problem. The next day I gave up on the property tree library after no success whatsoever, and I ended up doing the task using the witty JSON parser! The concept was very similar to the boost ptree library, and thus I started writing the code for the project very quickly. Successfully, I was able to parse and extract all the information needed from the JSON file.
I then started the last task, creating a new project from a POST request. The task consisted of many parts. First, receiving the request with two parameters. A fairly simple task.Then extracting a compressed project file to a temporary location. Here where things get tricky. However, some parts of the task were a bit unclear (or maybe I am just stupid), and since my supervisor was away for the week we couldn’t ask for clarification. I tried my best anyway, and I think I can finish what’s left once I understand the rest of the task. To generate the temporary directory we used boost filesystem library to generate a temporary path inside witty approot, and to generate a unique path, and then creating a folder at the path “approot/temporary path/unique path.” Then simply extracting the project file there using “system” function.
Next week I think I will continue in the back-end part of project. But there are many front-end issues I need to explore.
Feel free to drop any questions you have down in the comment section.
Valerij · 2015-07-18 at 03:43
Oh hey, thanks for this post. I just had the exact same problem with json+witty and wondered if someone found a solution. What’s weird is that the server crashes before read_json is even called; and doesn’t happen if I comment out the reading line. It also doesn’t happen when I build my project in Release/RelWithDebInfo mode. So I guess this is somewhat of an alternative solution.
Valerij · 2015-07-20 at 02:53
Well, I take that back. If you leave in boost’s read_json, you’ll eventually encounter strange errors (“Wt: fatal error: boost: mutex lock failed in pthread_mutex_lock: Invalid argument”) that mysteriously disappear when you switch to witty’s json parser.