wlav / cppyy

Other
401 stars 41 forks source link

retrieving a string is causing an access to null pointer error #7

Closed wassimj closed 2 years ago

wassimj commented 3 years ago

Hi, I distributed Topologic along with cppyy to three people and they all had VS 2019 installed and it worked fine, but they have encountered the following error which I do not see on my installation. Any hints on why this may be happening on their machines, but not mine? Is there something I can fix in my C++ code to avoid all this? This happens when they try to get a string value back from a dictionary. Thanks

2021-09-07 15:16:56,481 [WARNING] py.warnings: C:\Users\FILIPE\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\topologicsverchok\topologicPy\site-packages\cppyy\__init__.py:318: UserWarning: CPyCppyy API not found (tried: C:\Program Files\Blender Foundation\Blender 2.93\2.93\python\site\python3.9); set CPPYY_API_PATH envar to the 'CPyCppyy' API directory to fix
  warnings.warn("CPyCppyy API not found (tried: %s); set CPPYY_API_PATH envar to the 'CPyCppyy' API directory to fix" % apipath_extra)

IncrementalExecutor::executeFunction: symbol '?Value@StringAttribute@TopologicCore@@UEAAPEAXXZ' unresolved while linking symbol '__cf_28'!
You are probably missing the definition of public: virtual void * __ptr64 __cdecl TopologicCore::StringAttribute::Value(void) __ptr64
Maybe you need to load the corresponding shared library?
2021-09-07 15:19:19,473 [INFO] root: Initializing Sverchok logging. Blender version 2.93.4, Sverchok version 1.0.0
2021-09-07 15:19:19,473 [ERROR] topologicsverchok.nodes.Topologic.DictionaryValues:31 : attempt to access a null-pointer
wlav commented 3 years ago

The problem isn't with the string, but with the TopologicCore library having failed to load. That is, this function: void* TopologicCore::StringAttribute::Value(void) is missing which I presume is in libToplogicCore.dll?

(The string not being retrieved afterwards is a red herring: if the wrapper function fails to link, it simply returns a null value to prevent crashing when inspecting the result.)

Given that the CPyCppyy API was also not found, I suspect other installation issues. Is this code run from Blender? (There's a long thread on that one back on bitbucket.)

wassimj commented 3 years ago

But the strange thing is that other methods within the same run are working perfectly and they all are within TopologicCore. So for example they can retrieve the value if it is a float or int, but not if it is a string. Even on my machine the CPyCppy API is not found, but I don’t face this issue. And finally, yes this is all through Blender. Thanks

wlav commented 3 years ago

IIRC, IntAttribute etc. were pythonized to use IntValue etc. rather than Value. I note that in the headers methods such as IntValue are inline and thus visible to the compiler, no need for the linker to find them. The Value methods OTOH are out-of-line, so need to be linked. Windows requires all symbols used externally to a DLL to be exported. I see that the StringAttribute constructor is marked with TOPOLOGIC_API, but Value is not?

Any reason to not simply export the whole class? (I.e. declare the class with TOPOLOGIC_API?)

wassimj commented 3 years ago

A favour: can you please do a pull request at github.com/wassimj/Topologic so that the code is exactly as you think it should be? Many thanks!

wlav commented 3 years ago

I'd recommend simply exporting all symbols, such that the behavior on Windows is the same as on Linux and Mac. Use of cmake, which TopologicCore already does, makes that easy: https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html

Alternatively, add that TOPOLOGIC_API to each class that need exporting, just after the class keyword. I.e.: class TOPOLOGIC_API StringAttribute ....

Or finally, export that one function that is giving trouble here: TOPOLOGIC_API virtual void* Value(); in both StringAttribute and the Attribute base class (presumably, that will force the same in all Attribute derived classes, but I haven't tried (still no Windows box, although I now have an Intel Macbook on which I can run VMWare).

wlav commented 2 years ago

Presumed resolved after no feedback for more than a month.