AcademySoftwareFoundation / OpenShadingLanguage

Advanced shading language for production GI renderers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build error on MSVC with Partio

rasmusbonnedal opened this issue · comments

Problem

When OSL builds with Partio it gives an error on MSVC: https://gist.github.com/rasmusbonnedal/62c64d076a764b2f7c2ac07189501e49

This issue came when Pointcloud was marked OSLEXECPUBLIC because then MSVC needs all symbols of all members resolved. This makes it impossible to use unique_ptr in an STL container because the container has operations that access deleted members of the unique_ptr. (https://stackoverflow.com/questions/51033325/dll-exporting-causing-issues-with-unique-pointers). PointCloud has a member m_attributes of type std::unordered_map<ustringhash, std::unique_ptr<Partio::ParticleAttribute>> which causes the problem.

Could the unique_ptr be replaced with a shared_ptr?

Steps to Reproduce

  1. Build on Windows/MSVC with Partio enabled

Versions

  • OSL branch/version: main branch 2023-11-20
  • OS: Windows 10
  • C++ compiler: MSVC 19.29 (Visual Studio 2019)
  • LLVM version: 15.0.7
  • OIIO version: 2.5.5.0
  • Partio version: 1.17.1

Thanks for the stackoverflow link, they make the point that we may not need the default copy/move constructor or assignment operator and explictly deleting them may resolve the need for those private methods to be accessed.

I'll see if I can mock a reproducer in godbolt to confirm.

Reproducer with example of fix (delete default copy constructors and assignment operators):
https://www.godbolt.org/z/1GT478hE8

So to fix this just add the following to pointcould.h

    PointCloud(const PointCloud&) = delete;
    PointCloud(const PointCloud&&) = delete;
    PointCloud & operator=(const PointCloud&) = delete;
    PointCloud & operator=(const PointCloud&&) = delete;
    

Oh, that's a nice solution!

BTW, I think SortedPointRecord on pointcloud.h:58 should be std::pair<float, Partio::ParticleIndex> which gets rid of a warning.

I'll submit a PR for this.

BTW, I think SortedPointRecord on pointcloud.h:58 should be std::pair<float, Partio::ParticleIndex> which gets rid of a warning.

I believe it might have been intentionally an int vs. the Partio::ParticleIndex which is size_t to improve sorting performance. So choose to fix with adding proper static cast when constucting the SortedPointRecord.

Of course if the particle index > MAX_INT that would be a problem. Do we expect point clouds > 2 billion entries? If so... then maybe should be Partio::ParticleIndex. @lgritz , thoughts?

I think it should probably be ParticleIndex. I wonder if years ago, ParticleIndex was int and later changed to size_t?