It is currently April 19th, 2024, 3:09 pm

Plugin using multiple measures

Get help with creating, editing & fixing problems with skins
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Plugin using multiple measures

Post by chilio »

Hey everyone!

I finally found time to work on my little plugin again, and stuff went wrong again, how that always seems to happen when programming ^^'
When working with a single measure, everything seemed to go fine. I work in a child-parent relationship, where every class seems to initiate well, and the independent classes seem to update well as well. The problem arises when 2 measures with different types come around.

Code: Select all

    internal class Measure
    {
        internal static Measure MeasureFromData(API api, IntPtr data)
        {
            object x = GCHandle.FromIntPtr(data).Target;
            MeasureType measureType;
            Enum.TryParse(api.ReadString("Type", ""), true, out measureType);
            switch (measureType)
            {
                case MeasureType.ChildMeasure:
                    return (ChildMeasure)x;
                case MeasureType.ParentMeasure:
                    return (ParentMeasure)x;
                default:
                    return (Measure)x;
            }
        }
    }
An error (System.InvalidCastException: 'Unable to cast object of type 'PluginParentChild.ChildMeasure' to type 'PluginParentChild.ParentMeasure'.) will always show up in this piece of code, where the api seems to have a pointer to the wrong object. Seeing other plugins work, I won't believe that is the case, but I have no idea where to go from here.

Any ideas out there?

Thanks!
Chilio
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Plugin using multiple measures

Post by chilio »

Anyone?