Skip to content

Reading .ot (Visual Studio): tree type isn't registered therefore read() fails #51

Closed
@merfels

Description

@merfels

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions