-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading .ot (Visual Studio): tree type isn't registered therefore read() fails #51
Comments
Thanks for your detailed analysis. I agree that a cleaner solution would be preferable. What about adding
http://msdn.microsoft.com/en-us/library/chh3fb0k.aspx In any case, the smallest possible change that helps would be desirable since it has to be added to every derived octree class. |
I tried adding the volatile keyword and disabling optimization but that didn't help. I struggle to find out the real cause behind this behavior so finding a good solution is hard. If you have any more ideas then I'm happy to help you. |
Alas, I don't really know Visual Studio much (don't even have it running here) so I don't know how to tell their compiler to behave. There should be no reason to optimize that code out in the first place. I found some similar reports on the net, that's why I was hoping that either volatile or the optimize pragma would help: |
Thanks for the additional input. I agree that the compiler should not discard that code as it clearly has side-effects and it is kind of frustrating to find the right tweak to get it to work. For now, I will probably go for my own derived tree class with the workaround I proposed earlier, which isn't the cleanest solution but works just fine. |
I'm inclined to close this issue. The "test_color_tree" unit test succeeds with a current MSVC (Visual Studio 2013 and 2015, Win7 x64). Since I can't reproduce the issue I'm assuming it's fixed in the compiler. |
Closing the issue is fine with me. I am still using the proposed workaround under MSVC 2010. As I don't have MSVC 2013 or 2015, I can't confirm whether or not the test_color_tree unit test works there. |
Seems like that was too early, the problem still persists but manifests differently with MSVC 2013 / 2015. Now ColorOcTree works but no longer OcTree (causing test_io to fail). Here's another pointer that could work (actually your workaround hidden in a #define): |
Explicitly calling a dummy function from c'tor ensures that MSVC does not optimize the StaticMemberInitializer away. Extended and verified test_io to read / write OcTree, ColorOcTree and OcTreeStamped.
That's exactly how I implemented it and it works fine under VS 2010. I personally prefer to not put in a #define as things get less clear with more #define's. If people want to write their own tree implementation, they need to know what this workaround does. My suggestion is to put a comment in Doxygen explaining the issue and linking to this page. |
Yes, I agree that it's the best to have it as clear as possible! |
Fixes for IO factory class registry with MSVC (#51)
Merged into devel now, closing! |
is this problem solved now? |
System: Windows 8 64 bit, Visual Studio 2012, octomap-1.8.0, qt 5 #include <octomap/ColorOcTree.h> |
Yes, this should have been fixed already. Can you run the unit tests and post their output? There are specific tests for the classIdMapping, and last I checked they ran successfully under Windows. ColorOcTree.h is included from ColorOcTreeDrawer.h, which in turn is included through ViewerGui.cpp. |
Do you mean the result of the "ctest -C Release" command?
1/14 Test #1: MathVector ....................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 14 Total Test time (real) = 9.53 sec |
Which line exactly are you adding to ViewerGui.cpp? Can you submit a pull request with this (minimal) workaround? |
Ok. |
Thanks! |
Hi,
As discussed in the Google Groups, there seems to be an issue with Visual Studio and the File Factory pattern when trying to read in .ot trees. The expected behavior is that the tree type should be recognized when being read from file, but the static member initialization technique which should register the tree type doesn't work in this setup, which results in an unrecognized tree type when trying to load it.
System: Windows 7 64 bit, Windows SDK 7.1, Visual Studio 2010, octomap-1.6.1
Example which shows the behavior:
OcTree tree (0.01);
tree.write("simple_tree.ot");
AbstractOcTree * readTree = AbstractOcTree::read("simple_tree.ot");
if(readTree) {
OcTree * storedTree = dynamic_cast<OcTree*>(readTree);
} else {
// couldn't load tree
}
The tree can not be read in from file. The problem is that the instantiation of a new OcTree should result in the creation of the static StaticMemberInitializer ocTreeMemberInit which is defined in OcTree.h and subsequently register the tree type. Loading from file could then associate the stored file with this tree type. This seems to be an issue with the Visual Studio compiler.
One possible workaround is to put a function "void dummy() {} ;" in the class StaticMemberInitializer and calling it from within the OcTree constructor. I tried that and apparently this doesn't get optimized away, but it adds of course some bloat and is uncleaner / less comprehensible.
Best,
Christian
The text was updated successfully, but these errors were encountered: