forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Memory corruption when casting in .NET integration

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
alex21



Joined: 20 Apr 2011
Posts: 75
Location: Australia

PostPosted: Fri Jun 21, 2019 5:47 am    Post subject: Memory corruption when casting in .NET integration Reply with quote

Hello,

I posted about an issue with memory corruption when working with value types in collection previously: http://forums.silverfrost.com/viewtopic.php?t=3066

But still to this day my work around is not accessing booleans in a collection directly... as after posting an example showing the representation of booleans read from a .NET array were changing randomly because of how Silverfrost was reading the memory I never received a reply... That example project is no longer available as I did not maintain the dropbox account hosting it.

However I have grown increasingly frustrated with memory corruption issues in the .NET integration and have now noticed simply casting to value types actually pointed to by a collection/array is enough to run into this...

You can clone the solution containing the demonstration code below from: https://github.com/alexhopeoconnor/ftn_generic_collections_example.git

But I have defined the following type in the solution including my FTN project:
Code:

public class DataType
    {
        public List<string> DataList
        {
            get;
            set;
        }

        public List<int> IntDataList
        {
            get;
            set;
        }

        public List<double> DoubleDataList
        {
            get;
            set;
        }

        public DataType()
        {
            DataList = new List<string>() { "hello", "this", "is", "a", "test" };
            IntDataList = new List<int>() { 1, 2, 3, 4, 5, 640000 };
            DoubleDataList = new List<double>() { 1.1, 2.2, 3.3, 4.4, 5.5 };
        }
    }


In FTN if we were able to access non-wrapped generic types directly the following would compile:
Code:

! Initialize the dataType
    dataType = NEW@("Domain.DataType")

    ! Simple integration syntax won't work for generic types...... Won't even compile, need to wrap it as a non-generic type for it to work directly
    ! even though it implements non-generic interfaces (IList) with the same name as the member I am trying to access...
    !c = dataType%DataList%Count


So I have tried to use a wrapper written using reflection in .NET and calling it in FTN, but discovered when trying to cast from System.Object to a value type like System.Int32 memory is corrupted, when trying to do System.Object to System.Double it simply crashes after trying access protected memory, the following posts also address this issue:
http://forums.silverfrost.com/viewtopic.php?t=1965
http://forums.silverfrost.com/viewtopic.php?t=1963

So really I think there must be an issue with the compiler converting .NET types to 'intrinsic' (am I using that right?) FTN types, possibly something to do with the number of bytes it is reading from memory at the address in some situations because of the way these types are represented in different circumstances on the .NET side.

Please let me know if you need any further examples of these problems with the .NET integration and accessing generics or type conversion resulting in memory corruption.
Back to top
View user's profile Send private message MSN Messenger
Robert



Joined: 29 Nov 2006
Posts: 444
Location: Manchester

PostPosted: Fri Jun 21, 2019 9:40 am    Post subject: Reply with quote

I'll take a look at this problem.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group