Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SdfSimpleLayerStateDelegate is missing SDF_API tags #1969

Closed
fhechtAdobe opened this issue Jul 28, 2022 · 2 comments
Closed

SdfSimpleLayerStateDelegate is missing SDF_API tags #1969

fhechtAdobe opened this issue Jul 28, 2022 · 2 comments

Comments

@fhechtAdobe
Copy link

Description of Issue

For shared libraries on Windows all methods in the callable API need to be tagged with __declspec(dllexport), which for the Sdf library is done via the SDF_API macro as defined in pxr/usd/sdf/api.h.

Turns out when this was added to the headers of the Sdf library, a small utility class was missed: SdfSimpleLayerStateDelegate is declared in pxr/usd/sdf/layerStateDelegate.h and is used as the default state delegate for each SdfLayer.

But since the static SdfSimpleLayerStateDelegateRefPtr New(); call is missing the SDF_API tag it cannot be called from a piece of code that dynamically links against the Sdf library. At link time the symbol is missing. Which means this class can't be instantiated from the outside of Sdf.

For context, we have our own implementation of a SdfLayerStateDelegateBase to implement an undo system and when we disconnect our delegate we would like to reset it to the default implementation. Unfortunately we can't call the static New method on SdfSimpleLayerStateDelegate.

Steps to Reproduce

Try to compile the following on windows in a build unit that links dynamically against lib sdf.

#include <pxr/usd/sdf/layerStateDelegate.h>

PXR_NAMESPACE_USING_DIRECTIVE

void test() {
    SdfSimpleLayerStateDelegateRefPtr delegate = SdfSimpleLayerStateDelegate::New();
}

It should compile fine, but then get a linker error, since the New function is not exported.

error LNK2019: unresolved external symbol "public: static class pxrInternal_v0_22__pxrReserved__::TfRefPtr<class pxrInternal_v0_22__pxrReserved__::SdfSimpleLayerStateDelegate> __cdecl pxrInternal_v0_22__pxrReserved__::SdfSimpleLayerStateDelegate::New(void)" (?New@SdfSimpleLayerStateDelegate@pxrInternal_v0_22__pxrReserved__@@SA?AV?$TfRefPtr@VSdfSimpleLayerStateDelegate@pxrInternal_v0_22__pxrReserved__@@@2@XZ) referenced in function "void __cdecl `anonymous namespace'::test(void)" (?test@?A0x0c82cd52@@YAXXZ)

Workaround

A way to deal with this issue is to retain the SdfSimpleLayerStateDelegate, which is the default delegate for each SdfLayer via GetStateDelegate() and to restore it when we remove our custom state delegate.

System Information (OS, Hardware)

Windows only. Linux and MacOS are fine, since they handle symbols in dynamic libraries differently.

Package Versions

This was noted with a USD build from 22.08

Build Flags

Do let me know if you have any questions.

Thanks,
Florian

@sunyab
Copy link
Contributor

sunyab commented Jul 29, 2022

Hey @fhechtAdobe! Thanks for pointing this out, we'll get a fix out for this soon.

@sunyab
Copy link
Contributor

sunyab commented Aug 1, 2022

Filed as internal issue #USD-7528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants