I am currently troubleshooting an issue with my registered operator+ function returning garbage when it is used. I have not check the other operators I have defined yet for this same bug, this is the first.
It is possible it is a problem with AngelScript. I'll investigate this.
However you don't seem to register the dimension2df::operator= method, i.e.:
engine->RegisterObjectMethod("dim2f", "dim2f &opAssign(const dim2f &in)", asMETHODPR(dimension2df, operator=, (const dimension2df &), dimension2df &), asCALL_THISCALL);
It really shouldn't be necessary to register it, as you registered the type as asOBJ_POD, but there might be a problem in AngelScript so if you could give it a try and let me know if it works it would help me identify the problem.
[EDIT] I tried to reproduce this problem, but wasn't able to. What compiler are you using and what is your operative system?
Can you set a break point in the operator+ method and check if the input is correct? That at least would help narrow down where the problem might be.
Because it is a template function I tried to overload the assign with all the reasonable dim2X variable types. It should pick the float when it tries to find the right function.
I am using CodeBlocks 10.5 with MinGW. Did you mean a break point on the script function itself? How would I do that? All the registrations are native, so there are no wrapper functions...
No, I meant a break point in the C++ method dimension2d<T>::operator+. When it stops there, check the this pointer and the argument to see if they have proper values.
OK, so the opAssign method is registered. Do the script work if you write the following?
I apologize if I am being too verbose in my troubleshooting efforts, I figured you'd want all the information possible. So I looked at how the constructor was receiving the arguments and tried twiddling around with the reference operators.
...it made no difference, the constructor sees the exact same value for self. I am stumped at this point...I don't understand why it doesn't get the correct value...
That changing the signature to return the value by & indicates that AngelScript is thinking the dimension2df type must be returned in memory (thus passing a hidden pointer as the first argument to the function).
This tells me there is a problem with the configuration for MinGW on Windows in as_config.h.
The constructors didn't have any problem, neither the assignment operator. You've already shown that with your tests. The only problem seems to be when the method returns the type by value.
Would it be possible for you to run the test_feature project with your compiler to check which tests in the main.cpp that fail?
That changing the signature to return the value by & indicates that AngelScript is thinking the dimension2df type must be returned in memory (thus passing a hidden pointer as the first argument to the function).
This tells me there is a problem with the configuration for MinGW on Windows in as_config.h.
The constructors didn't have any problem, neither the assignment operator. You've already shown that with your tests. The only problem seems to be when the method returns the type by value.
Would it be possible for you to run the test_feature project with your compiler to check which tests in the main.cpp that fail?
During the compile of the "test_feature" project, the compiler failed on the following:
E:\pb\angelscript_2.21.0\tests\test_feature\source\test_registertype.cpp||In function 'bool TestRegisterType::TestHandleType()':|
E:\pb\angelscript_2.21.0\tests\test_feature\source\test_registertype.cpp|889|error: 'asOBJ_ASHANDLE' was not declared in this scope|