SDK compatibility issues in VS2019 C++ project with std::string

Discussion related to the LuxCore functionality, implementations and API.
MMatteini
Posts: 6
Joined: Fri Mar 19, 2021 10:55 am

SDK compatibility issues in VS2019 C++ project with std::string

Post by MMatteini »

Hi,
i'm new to this forum, and to LuxCore!

I registered because I'm working to integrate LuxCore renderer into another c++ software as a test, but i'm encountering few issues with the distributed builds of the SDK, I also tried to re-build to no avail:

What i did to rebuild:
git clone https://github.com/LuxCoreRender/LuxCore
git clone https://github.com/LuxCoreRender/WindowsCompile
and then in the visual studio 2019 console:
.\cmake-build-x64.bat /dll /debug /vs2019
following the tutorial found here:
https://github.com/LuxCoreRender/WindowsCompile

The build works fine, i also tried the compiled luxcoreui.exe to launch some test scenes and it works!
The issue is that when i try to use the luxcore.DLL in my project, std::string create corruption, e.g. :

PropertyValue propVal = 6; // works fine!
PropertyValue propVal = "test string"; // propVal is corrupted....

This is probably due to some incompatibility / alignment issue with how my project is build...
I was also reading this topic: viewtopic.php?t=1013 where another user had similar issues, but it's not clear if he solved or not.

My project is using the same platform tooset (v142) used fo the build and i tried with both debug and release builds, what do you think is causing the issue? Any suggestion would be very much appreciated!
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by Dade »

May be a problem related to UTF-8 Vs UTF-16 ? Does VS2019 something strage with std::string ? Like using std::wstring instead ?
Support LuxCoreRender project with salts and bounties
MMatteini
Posts: 6
Joined: Fri Mar 19, 2021 10:55 am

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by MMatteini »

Thanks for your reply!
I think that should actually be fine, since to test it i created an empty c++ project, in which i just copied the luxcoredemo.cpp test code from the luxcoredemo project, slightly modified to avoid using boost, here is the code:
TestCode.cpp
(7.78 KiB) Downloaded 181 times
, std::string should be the same...
acasta69
Developer
Developer
Posts: 472
Joined: Tue Jan 09, 2018 3:45 pm
Location: Italy

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by acasta69 »

I think you are referring to the output of this:

Code: Select all

PropertyValue propVal = "test string";
Property prop("test1.prop1", propVal);
cout << "test1.prop1[0] => " << prop.Get<string>(0) << "\n\n";
What do you get as output when the value is corrupted?

I did a naive test, building luxcoredemo with VS2017 and VS2019 and comparing the output.
They are identical and look both strange to me, but I could be wrong as I don't know so well the Luxcore API.
From these lines in luxcoredemo.cpp:

Code: Select all

Property prop("test1.prop1", "aa");
cout << "test1.prop1[0] => " << prop.Get<string>(0) << "\n\n";
I would imagine to get this output:

Code: Select all

test1.prop1[0] => aa
Dade, is this correct?
This is what I get instead, with both Visual Studio versions:

Code: Select all

test1.prop1[0] => 1
Support LuxCoreRender project with salts and bounties

Windows 10 64 bits, i7-4770 3.4 GHz, RAM 16 GB, GTX 970 4GB v445.87
Ernest
Posts: 9
Joined: Sun Mar 31, 2019 11:30 am

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by Ernest »

Hello MMatteini,

looks like you run into the same problem as I did. I assume you work with the Debug configuration of VS. In this case the _DEBUG switch is active which leads to some modifications to the STL components by introducing additional security checks by MS. This makes your code incompatible with libraries not compiled with this switch (like luxcore especially in Release builds) due to different memory layout of objects. I solved it by also removing the _DEBUG switch in my interface library and using boost::string to transfer strings to this library. In my case luxcore works then without problems.

Hope this helps also in your case. Feel free to ask for more details.
MMatteini
Posts: 6
Joined: Fri Mar 19, 2021 10:55 am

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by MMatteini »

acasta69 wrote: Fri Mar 19, 2021 6:13 pm What do you get as output when the value is corrupted?
Hi, thanks for your tests!
Unfortunately i don't even get that far, since after:

Code: Select all

Property prop("test1.prop1", "aa");
prop is already corrupted, with dataType==BOOL_VAL(1) and the string field assigned to an invalid pointer. If i try to initialize a property with that value i get an exception "ERROR: bad allocation"...
Ernest wrote: Sun Mar 21, 2021 8:55 pm I assume you work with the Debug configuration of VS. In this case the _DEBUG switch is active which leads to some modifications to the STL components...
Hi Ernest, I was hoping to know how you solved! your problem was indeed similar. The _DEBUG switch is the first thing i tried after reading your post, actually I copy/replaced all the preproc definitions in my project to match the ones from luxcore, just to be sure, I also tried to build both luxcore and my project in Debug and the Release, but no combination of the above worked...
Which toolset did you end up using? (I'm building with v142)
acasta69
Developer
Developer
Posts: 472
Joined: Tue Jan 09, 2018 3:45 pm
Location: Italy

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by acasta69 »

MMatteini wrote: Mon Mar 22, 2021 8:16 am prop is already corrupted, with dataType==BOOL_VAL(1)
That is also what I am seeing: that piece of data is recognized as BOOL_VAL, and then the corresponding output is:

Code: Select all

test1.prop1[0] => 1
I have no "bad allocation" error though.

Yesterday I compiled it also in a Linux VM and result is the same.

One thing I have seen is that, later in the luxcoredemo.cpp code, other string examples are handled with the "string" type:

Code: Select all

// String tests
const string testStr("TEST123");
Property p0("string.test", testStr);
Maybe character strings like "aa" are not automatically converted to "string" type before being used by PropertyValue / Property?
I am not sure if this makes sense, please forgive my little knowledge of C++ :oops:
Support LuxCoreRender project with salts and bounties

Windows 10 64 bits, i7-4770 3.4 GHz, RAM 16 GB, GTX 970 4GB v445.87
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by Dade »

acasta69 wrote: Mon Mar 22, 2021 4:00 pm Maybe character strings like "aa" are not automatically converted to "string" type before being used by PropertyValue / Property?
I am not sure if this makes sense, please forgive my little knowledge of C++ :oops:
"aa" is "char *" while std::string is a different type, do you get the same error if you use something like "string("aa")" instead of "aa" ?
Support LuxCoreRender project with salts and bounties
MMatteini
Posts: 6
Joined: Fri Mar 19, 2021 10:55 am

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by MMatteini »

Dade wrote: Mon Mar 22, 2021 4:49 pm "aa" is "char *" while std::string is a different type, do you get the same error if you use something like "string("aa")" instead of "aa" ?
I tried, and unfortunately i do...

I put toghether the most minimal VS2019 project that include an SDK build to show the issue, i'll attach it to this post, you only have to replace lib/ and include/ folders with the ones from the sdk build (i didn't inlcude my build to keep the size small, but the 2.4 sdk from the download section show the same issue).
I just created a new console project, added includes and luxcore.lib, and removed _DEBUG as suggested by Ernest!
If i can make this minimal test work, by either creating a compatible sdk build, or adjusting the test project my issue is solved :)
Attachments
LuxcoreSdkMinimalTest.zip
(30.07 KiB) Downloaded 155 times
acasta69
Developer
Developer
Posts: 472
Joined: Tue Jan 09, 2018 3:45 pm
Location: Italy

Re: SDK compatibility issues in VS2019 C++ project with std::string

Post by acasta69 »

MMatteini wrote: Tue Mar 23, 2021 9:05 am
Dade wrote: Mon Mar 22, 2021 4:49 pm "aa" is "char *" while std::string is a different type, do you get the same error if you use something like "string("aa")" instead of "aa" ?
I tried, and unfortunately i do...
I also tried and it's working here, both VS2017 and VS2019.
Code:

Code: Select all

Property prop("test1.prop1", string("aa"));
cout << "test1.prop1[0] => " << prop.Get<string>(0) << "\n\n";
Output:

Code: Select all

test1.prop1[0] => aa
This was done modifying the original LuxCoreDemo.
I will test with your project as soon as possible.
Support LuxCoreRender project with salts and bounties

Windows 10 64 bits, i7-4770 3.4 GHz, RAM 16 GB, GTX 970 4GB v445.87
Post Reply