Code Monkey home page Code Monkey logo

Comments (9)

EgorBo avatar EgorBo commented on June 7, 2024

Looks like this line of code causes the crash: https://github.com/xamarin/urho/blob/master/Samples/Samples/InProgress/02_HelloGUI.cs#L174 if (comment only L174 - the crash won't reproduce)

Thus the problem is in the:

[DllImport ("mono-urho")]
internal static extern string UIElement_GetName (IntPtr handle);

from urho.

EgorBo avatar EgorBo commented on June 7, 2024

Probably, all bridge.cpp methods returning const char * have same behavior.

from urho.

EgorBo avatar EgorBo commented on June 7, 2024

Can be fixed by duplicating string:

DllExport const char *
UIElement_GetName (Urho3D::UIElement *_target)
{
    return _target->GetName ().CString ();
}

to

DllExport const char *
UIElement_GetName (Urho3D::UIElement *_target)
{
    return strdup (_target->GetName ().CString ());
}

from urho.

EgorBo avatar EgorBo commented on June 7, 2024

better solution without strdup:

[DllImport ("mono-urho", CallingConvention = CallingConvention.Cdecl)]
internal static extern string UIElement_GetName (IntPtr handle);

private string GetName ()
{
       return UIElement_GetName (handle);
}

to

[DllImport ("mono-urho", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr UIElement_GetName (IntPtr handle);

private string GetName ()
{
       return Marshal.PtrToStringAnsi(UIElement_GetName (handle));
}

from urho.

EgorBo avatar EgorBo commented on June 7, 2024

umm... this also works (setting CharSet):

[DllImport ("mono-urho", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
internal static extern string UIElement_GetName (IntPtr handle);

from urho.

EgorBo avatar EgorBo commented on June 7, 2024

Fixed with strdup.

from urho.

Therzok avatar Therzok commented on June 7, 2024

Late to the party, but wouldn't a custom marshaller work better than strduping?

https://github.com/libgit2/libgit2sharp/blob/vNext/LibGit2Sharp/Core/Utf8Marshaler.cs#L18

from urho.

Therzok avatar Therzok commented on June 7, 2024

@migueldeicaza ^

The reasoning is not leaking anything in case something in Urho itself calls methods which would do the strdup, but never clean it up.

from urho.

migueldeicaza avatar migueldeicaza commented on June 7, 2024

I think that would work, I will keep it in mind. I need to measure if the generated code would be larger than what we have (in particular on iOS)

from urho.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.