Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by avvie · Feb 23, 2018 at 02:02 PM · androidserializationstruct

Serialization: Marshal.StructureToPtr does not work "always"

Hi.

I am using unity 2017.2.0f3. In the editor i have no issues whatsoever. When I started testing a build on android though it didnt work on 1 structure. It still works perfectly well on all other structs i am using. but the app crashes and produces no output from logcat.

The struct in question is:

 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode, Pack=1)]
     [Serializable]
     public struct Stage{
         public int stageNumber;
         public int realScore;
         [MarshalAs(UnmanagedType.Bool)]
         public bool quits;
         public int stars;
         public float timeSpent;
         [MarshalAs(UnmanagedType.Bool)]
         public bool isMixed;
         [MarshalAs(UnmanagedType.Bool)]
         public bool isTest;
         [MarshalAs(UnmanagedType.Bool)]
         public bool needstoUpload;
         public int associatedSessionNumber;
         public int numberOfMoves;
         public int stageCount;
         [MarshalAs(UnmanagedType.Bool)]
         public bool win;
         public UInt32 result;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
         public string wordCategory;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 33)]
         public string profileId;
         [MarshalAs(UnmanagedType.ByValArray, SizeConst=10)]
         public int[] score;

}|

The serialization that works on editor and on device for the other structs is:

 public static byte[] RawSerialize(object anything)
     {
         Debug.Log("a1");
         int rawSize = Marshal.SizeOf(anything);
         Debug.Log("a2");
         IntPtr buffer = Marshal.AllocHGlobal(rawSize);
         Debug.Log("a3");
         Marshal.StructureToPtr(anything, buffer, false);
         Debug.Log("a4");
         byte[] rawDatas = new byte[rawSize];
         Debug.Log("a5");
         Marshal.Copy(buffer, rawDatas, 0, rawSize);
         Debug.Log("a6");
         Marshal.FreeHGlobal(buffer);
         Debug.Log("a7");
         return rawDatas;
     }


Pardon the debug logs, but since logcat had no output on the crash I had to go this way "a3" is the last output when i serialize the stage struct. All other structs have basically the same structure and produce no problems. They have array definitions and other [...] statements with the same char encodings, packing bytes and types.

If any wizard can provide some light to the situation, I would be grateful.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image avvie · Feb 23, 2018 at 03:33 PM 0
Share

$$anonymous$$anaged to fix it by using IL2CPP.. I managed to figure out that the problem was a SIGSEGV but I have no idea why it happens on that specific struct and not on the others. So i ll leave the question open for the time

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

168 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to save ComputeBuffer? 0 Answers

Stuck on splash screen on Android only 0 Answers

Is it possible to serialize and store custom structs on the iPhone in scriptableObjects? 2 Answers

Problem to add a delete method to a saveload script C# 3 Answers

Serializing to disk sometimes fails on Android, but on iOS works fine 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges