Message thread on Webots Programming

[C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Chansol Hong (Webots PRO - 5) 2017-04-18 15:45:00
My OS: Windows 10 (also tested some portion in Ubuntu 16.04)
My license type: PRO
My Webots version number: 8.5.4

Hello,

I was trying to learn how to set the translation and rotation fields of other nodes using the supervisor and realized that setSFVec3f() and setSFRotation() methods are sometimes not setting the corresponding fields to the values I actually assigned. For example, I tried to set the rotation field of the supervisor's child camera to {-1, 0, 0, 1.5707964} using setSFRotation() method, but the camera's rotation field was set to {3.6624335e-317, 8.1711584e-315, 0, 1.5707964} instead.

I have tried several different ways and found out that this behavior is only appearing in some certain cases. The attachment is the wbt file for my world and the supervisor controller that tries to set the translation and rotation fields of its child camera in several different ways. Please refer to the attachment when reading below.

My test_supervisor class (defined in the supervisor code "controllers/Super/Super.cpp") has five similar methods (init_camera(), init_camera2(), ..., init_camera5()) that try to fetch the camera node, its translation and rotation fields, and set the fields to certain values using setSFVec3f() and setSFRotation() methods, respectively.

init_camera() is defined in the class definition while other four are defined outside of the class definition

1. init_camera()

This method is defined directly in test_supervisor class definition. It is working correctly.


2. init_camera2()

This method is declared in test_supervisor class and defined at the outside of the class definition. This method is NOT working correctly although its contents are identical to init_camera()'s contents. It sets the translation and rotation fields of the camera to values different from what I assigned.


3. init_camera3()

It is almost same as init_camera2() but 'inline' is used at this method's declaration in test_supervisor class definition. This method is working correctly.


4. init_camera4()

This method is almost same as not-working-method init_camera2() but getSFVec3f() and getSFRotation() methods are called directly after setSFVec3f() and setSFRotation() methods, respectively. Although these method calls are inserted there for no actual use, they somehow make the method work correctly.


5. init_camera5()

This method replaced local variables with test_supervisor class member variables. This method is working correctly.


For me, it seems the only difference between init_camera2() and other methods except init_camera4() is whether setSF****() methods' input variables are defined inline(?) or not. I am not sure why this difference is making setSF****() methods not working correctly in init_camera2()'s case. Can someone please teach me the reason behind this?

In init_camera4()'s case, I have no idea at all why it is working correctly.

Attachment: testworld.zip.
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Fabien Rohrer (Webots PRO - 1186) 2017-04-20 10:55:06
Hi,

Thank you for this precise bug report.

I tried your example both on Mac and Windows 10 with Webots 8.5.4, and unfortunately I didn't reproduced it. init_camera2() is working well on my environments. In this case it will be very difficult to elaborate good hypothesis. It seems to be related with some weird timing issue.

- Could it be possible that your use of std::shared_ptr could imply issues (I'm telling this because I'm not used to this) => What if you directly instantiate the Supervisor class?
- What is occurring if you build in debug mode (in the Makefile: CFLAGS += -g)?

Sincerely,
Fabien Rohrer
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Fabien Rohrer (Webots PRO - 1186) 2017-04-20 11:20:51
I just reproduced the bug on Windows, so I could go further. I will keep you in touch there when I have some news.
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Fabien Rohrer (Webots PRO - 1186) 2017-04-20 14:27:01
I confirm there is a bug in Webots 8.5.4 about a possible memory corruption on the supervisor fields setters; I just fixed it in our development version. Could I ask you to unzip the attached file, and copy it to "C:\Programs Files\Webots\msys64\mingw64\bin\Controller.dll"? (I hope this file is compatible with your system, if this is not the case, we will send you a beta version of Webots 8.5.5)

Attachment: Controller.dll.zip.
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Chansol Hong (Webots PRO - 5) 2017-04-20 17:17:06
Thanks a lot Fabien!

I have tried the attached dll file on my system and it worked well!
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Fabien Rohrer (Webots PRO - 1186) 2017-04-20 17:32:31
Thank you for the feedback, and don't hesitate to send us again so precise bug reports ;-)
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Chansol Hong (Webots PRO - 5) 2017-04-20 17:35:57
By the way, I was working on Webots 8.5.4 in Ubuntu 16.04 yesterday and found that it had the same problem there too. Will the bug also be fixed on the new Webots version on Linux?
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Fabien Rohrer (Webots PRO - 1186) 2017-04-20 17:41:26
Yes, the source code is globally identical between OSs and we release all the packages at the same time. As this bug is quite serious, I think we will release very soon. But if this is blocking for you, we can send you a libController.so as I just did for Windows.
Re: [C++] class Field's setSF****() method sets the value incorrectly in some certain casesby Chansol Hong (Webots PRO - 5) 2017-04-22 08:46:45
I can wait for the next release as I could just move some methods into the class definition as a workaround. Still, thank you for your kind response! I really appreciate it!.
You need to log in to be able to reply, subscribe or unsubscribe to this thread