Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Some methods returning base structs (Vector, Quaternion, etc) cause AccessViolationException #54

Closed
EgorBo opened this issue Aug 11, 2015 · 1 comment
Labels

Comments

@EgorBo
Copy link
Member

EgorBo commented Aug 11, 2015

Let's take a look at Node type.
When CxxBinders sees

const Vector3& GetPosition() const { return position_; }

it generates:

DllExport Interop::Vector3 
Node_GetPosition (Urho3D::Node *_target)
{
    return *((Interop::Vector3  *) &(_target->GetPosition ()));
}

(converts Urho3D::Vector3 to Interop::Vector3 and everything is OK).

BUT when it sees:

Vector2 GetPosition2D() const { return Vector2(position_.x_, position_.y_); }

(returns a new instance on each call)
it generates:

DllExport Urho3D::Vector2
Node_GetPosition2D (Urho3D::Node *_target)
{
    return _target->GetPosition2D ();
}

and it won't work (managed code will get a corrupted piece of memory)
it can be fixed if the CxxBinder generates it something like this:

DllExport Interop::Vector2
Node_GetPosition2D (Urho3D::Node *_target)
{
    return *((Interop::Vector2 *) &(_target->GetPosition2D ()));
}

I guess it should be fixed here: (for all basic types: Vector2, Vector3, etc) https://github.com/xamarin/urho/blob/master/SharpieBinder/CxxBinder.cs#L1071

@EgorBo
Copy link
Member Author

EgorBo commented Aug 11, 2015

closing with #54 with fix 85b3fc0 fix is verified.

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

No branches or pull requests

1 participant