Write access exception when compiling as a DLL on Windows


I’ve tried to compile OpenNurbs 7 (this version) as a DLL on Windows. When linking with a simple program that just calls ON::Begin(); ON::End();, I am hitting a write access exception in the ON_StackedText destructor (link).

The destructor is being called on ON_StackedText::Empty (defined here; constructed here). ON_StackedText::Empty is a static const, so it is placed in a read-only section of the DLL (.rdata). As a result, when the program tries to write to the const object’s member m_top_run, a write access exception is triggered, because a write is being attempted on a read-only memory page.

Here is a git repository that reproduces the issue on my machine: pelletier/opennurbs-write-bug. I’m running MSVC 14.25.28610 (from Visual Studio 2019) on Windows 10.

I have two pretty ugly workarounds at the moment (without patching OpenNurbs):

  • make the page where ON_StackedText::Empty is stored writable (patch).
  • have the linker make the DLL’s .rdata section writable (patch).

Can you confirm this is a bug or am I building it wrong? :slight_smile:

Thank you!

It’s a bug that recently showed up with the latest release of Visual Studio. We have fixed the destructors in our internal codebase for Rhino. @will we probably need to push new source to public opennurbs.

:point_up: I can confirm that version builds and runs well on MSVC 14.25.28610. Thanks for releasing it!


I’ve created bug for this but maybe there was already one?