Ошибка сегментации при использовании функции драйвера - PullRequest
1 голос
/ 24 сентября 2019

Произошла ошибка сегментации при попытке использовать функцию драйвера.

main.cpp

int main(int ac, char* av[])
{
    FltkWindow fl;
    fl.test(inputDirPathString , outputDirPathString, isProcessScans, isCreateProjectPointCloud, isTruncateBigCoordinates, isRenameImportedScans, false);
    return EXIT_SUCCESS;
}

FltkWindow.hpp

class FltkWindow {
public:
    void test(const std::string&, const std::string&, bool, bool, bool, bool, bool);

protected:
    // members
    std::mutex m_mutex;
    std::ofstream m_logfile;
    void truncateBigCoordinates(const ref_ptr<LSProject> pProject);
    void renameScans(const ref_ptr<LSWorkspace>, const std::string&, const std::string&);
    void renameScans(const ref_ptr<LSProject>, const std::string&);
    void renameScans(const ref_ptr<LSProject>);

};

#endif


FltkWindow.cpp

void FltkWindow::test(const std::string& m_pInputDir_value, const std::string& m_pOutputDir_value, bool isProcessScans, bool isCreateProjectPointCloud, bool isTruncateBigCoordinates, bool isRenameImportedScans, bool isCancel){

    const std::string& strInputDir = m_pInputDir_value;
    const std::string& strOutputDir = m_pOutputDir_value;

    const std::wstring wstrOutputDir(strOutputDir.begin(), strOutputDir.end());

    const double fInputSizeInGB = getDataSizeInGB(strInputDir);
    double fProcessedSizeInGB = 0.0;

// find all e57 files in input dir structure
    for (const auto& dirEntry : std::experimental::filesystem::recursive_directory_iterator(strInputDir, std::experimental::filesystem::directory_options::follow_directory_symlink))
    {
        if (std::experimental::filesystem::is_regular_file(dirEntry))
        {
            const std::experimental::filesystem::path filepath(dirEntry);
            if ( filepath.extension() == ".e57" )
            {
                try
                {
                    const std::string& strUuid = createUuid();
                    const std::string& strProjectDir = strOutputDir + "/" + filepath.stem().string() + "-" + strUuid;
                    std::experimental::filesystem::create_directories(strProjectDir);
                    {
                        std::lock_guard< std::mutex > lock(m_mutex);
                        m_logfile = std::ofstream(strProjectDir + "/pointcloudbuilder.log");
                    }

                    std::cout << "Starting processing of file. " << std::endl;
                    // 1. create and load project
                    const std::wstring wstrUuid(strUuid.begin(), strUuid.end());
                    if (LSProject::createProject(wstrOutputDir.c_str() + LSString( L"//") + filepath.stem().c_str() + LSString(L"-") + wstrUuid.c_str(), filepath.stem().c_str()) != LSResult::Ok)
                    {
                        std::cout << "Unable to create project. Continuing with next file" << std::endl;
                        continue;
                    }

                    ref_ptr< LSProject > pProject(nullptr);
                    const LSString& strProjectPath = wstrOutputDir.c_str() + LSString( L"//") + filepath.stem().c_str() + LSString(L"-") + wstrUuid.c_str() + LSString(L"//") + filepath.stem().c_str() + LSString(L".lsproj");

                    if (LSProject::loadProject(strProjectPath, pProject) != LSResult::Ok)
                    {
                        std::cout << "Unable to load project. Continuing with next file" << std::endl;
                        continue;
                    }
                    std::cout << "Project successfully created \n";

                    // 2. import file
                    std::cout << "Importing file " << filepath.string() << " \n";
                    if (!pProject->importData(filepath.wstring().c_str()))
                    {
                        std::cout << "Unable to import given input data. Continuing with next file.\n";
                        continue;
                    }
                    std::cout << "Finished data import.\n";

                    if (isTruncateBigCoordinates){
                        truncateBigCoordinates(pProject);
                    }

                    // 3. save project
                    if (pProject->saveRevision(getCreatedCommitMessage().c_str(), getAuthor().c_str()) != LSResult::Ok)
                    {
                        std::cout << "Unable to save to a new revision. Continuing with next file.  \n";
                        continue;
                    }
                    std::cout << "Project saved. \n";

                    if (isProcessScans)
                    {
                        // For each "scan object": create Scan Pointcloud.
                        std::cout << "Starting to process all scans \n";
                        const std::vector< ref_ptr< LSScan > >& vScans = pProject->getScans().get();
                        for (ref_ptr< LSScan > pScan : vScans)
                        {
                            if (processScan(*pScan, true) != LSResult::Ok)
                            {
                                std::cout << "Unable to process scan " << std::string(pScan->getName().toCharStr()) << ". Continuing with next scan. \n";
                                continue;
                            }
                        }
                        std::cout << "Finished processing all scans \n";
                        // Save project
                        if (pProject->saveRevision(getScansProcessedCommitMessage().c_str(), getAuthor().c_str()) != LSResult::Ok)
                        {
                            std::cout << "Unable to save to a new revision. Continuing with next file.\n ";
                            continue;
                        }
                    }

                    if (isCreateProjectPointCloud)
                    {
                        pProject->createPointCloud();
                        std::cout << "Project Point cloud created. \n";

                        // Save project
                        if (pProject->saveRevision(getCloudCreatedCommitMessage().c_str(), getAuthor().c_str()) != LSResult::Ok)
                        {
                            std::cout << "Unable to save to a new revision. Continuing with next file.  \n";
                            continue;
                        }
                        std::cout << "Project saved. \n";
                    }

                    // rename scans and save project
                    if (isRenameImportedScans)
                    {
                        std::cout << "Renaming scans now.\n";
                        renameScans(pProject);
                        if (pProject->saveRevision(getRenamedScansCommitMessage().c_str(), getAuthor().c_str()) != LSResult::Ok)
                        {
                            std::cout << "Unable to save revision. Continuing with next file.\n";
                            continue;
                        }
                        std::cout << "Project saved. \n";                   }

                    const size_t nBytes = std::experimental::filesystem::file_size(filepath);
                    fProcessedSizeInGB += (nBytes * fBytesToGBFactor);

                    std::cout << "Progress " << std::to_string(fProcessedSizeInGB) << " GB from " << std::to_string(fInputSizeInGB) << " GB. \n";

            }
                catch (const std::exception& e)
                {
                    std::cout << "Standard exception: " << std::string(e.what()) << ". Abort processing of current file. \n";
                }
                catch (...)
                {
                    std::cout << "Unknown exception: Abort processing of current file. \n";
                }
            }
        }
    }

    std::lock_guard< std::mutex > lock(m_mutex);
    m_logfile.close();
}

В частности, именно эти две строки в FltkWindow.cpp вызывают ошибку сегментации, но я понятия не имею, почему:

const LSString& strProjectPath = wstrOutputDir.c_str() + LSString( L"//") + filepath.stem().c_str() + LSString(L"-") + wstrUuid.c_str() + LSString(L"//") + filepath.stem().c_str() + LSString(L".lsproj");

LSProject::loadProject(strProjectPath, pProject) 

Функция loadProject происходит из API, но яЯ уверен, что ошибка сегментации не вызвана этим.Я полагал, что ошибка сегментации исходила из этой части кода, как когда я изменил переменную strProjectPath, программа работала нормально.

Дополнительная информация о ref_ptr: http://developer.faro.com/api/v2-0/documentation/general-documentation/fundamental-data-structures.

Также, как я вызываю класс FltkWindow, используя fl.test (...) правильно?

...