isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.33k stars 2.29k forks source link

Error passing strings to functions #6863

Closed AlexandreLaborde closed 2 months ago

AlexandreLaborde commented 3 months ago

Checklist

Describe the issue

I built the C++ version of the library for windows and appears to working well, except I cannot pass strings to methods. This can be seen for instance when loading a point cloud from a file. The call occurs fine but the strings with filename and format are broken so it fails to load the files.

I modified the open3d code and hardcode the path it loads the data without issues so the issue is related to passing the string to function 🤷

This issue even prevents the logger from printing data.

Can anyone please shine some ideas on this weird issue ?

Steps to reproduce the bug

There's much to reproduce this is all my code.

int main(){
const std::string filepath = "<...>/vertices.xyz";
const string format = "xyz";

cout << filepath << endl;
std::shared_ptr<geometry::PointCloud> source = open3d::io::CreatePointCloudFromFile(filepath, format);
}

If I modify CreatePointCloudFromFile from the original :

std::shared_ptr<geometry::PointCloud> CreatePointCloudFromFile(
        const std::string &filename,
        const std::string &format,
        bool print_progress) {
    auto pointcloud = std::make_shared<geometry::PointCloud>();
    ReadPointCloud(filename, *pointcloud, {format, true, true, print_progress});
    return pointcloud;
}

to :

std::shared_ptr<geometry::PointCloud> CreatePointCloudFromFile(
        const std::string &filename,
        const std::string &format,
        bool print_progress) {
    auto pointcloud = std::make_shared<geometry::PointCloud>();

    const std::string path = "<...>/vertices.xyz";
    const std::string fmt = "xyz";

    ReadPointCloud(path, *pointcloud, {fmt, true, true, print_progress});
    return pointcloud;
}

It loads the point cloud without issues.

Error message

[Open3D DEBUG] Format File [Open3D WARNING] Read geometry::PointCloud failed: unknown file extension for (format: ).

Expected behavior

No response

Open3D, Python and System information

- Operating system: Windows 11 64-bit
- Python version: Python 3.11 
- System architecture: x86 
- Is this a remote workstation?: no
- How did you install Open3D?: build from source
- Compiler version (if built from source): cmake 3.30.0

Additional information

No response

rxba commented 3 months ago

Hey @AlexandreLaborde , I've tried it and was not able to reproduce this issue, albeit on ARM MacOS. The following minimal example runs without any issues for me:

#include <string>
#include <iostream>
#include "open3d/io/PointCloudIO.h"

int main(int argc, char *argv[]) {
    const std::string path = "../test.pcd";
    const std::string format = "pcd";

    std::cout << path << std::endl;
    std::shared_ptr<open3d::geometry::PointCloud> pcl = open3d::io::CreatePointCloudFromFile(path, format);
    return 0;
}

Since the warning indicates empty strings have been passed as filepath and format, are you sure that both contain the correct data the moment you call CreatePointCloudFromFile(..)?

AlexandreLaborde commented 2 months ago

Thanks for helping me sort this out. Everything is okay with the file since I can open it in other programs. In fact if I add a new method the open3d library that loads the same file it works without any issues. But If pass the path as a parameter it does not work.

I am very confident that is a windows only issue as it appears a bit left behind compared to the linux version. At the moment its not even possible to build the library without modifying several files.

I ran your code to illustrate what happens. image

The interesting part is that depending on how the path is described I seem to get different errors. image

image

AlexandreLaborde commented 2 months ago

Finally found out the solution! Visual Studio does not like when the DLL you are importing is built for Release and you are consuming it in a application in Debug mode. I built open3d in Debug and it works now.