Unity 4.5 Memory Stream is Corrupted

Updating to 4.5 from 4.3.4 is causing a crashing error when loading most scenes in our game. Whenever loading them in game or trying to open the Editor scene files, it causes:

Fatal Error
The file ‘MemoryStream’ is corrupted! Remove it and launch unity again!
[Position out of bounds! 20 > 16]
UnityEditor.DockArea:OnGUI()

== LOG FILE ==
The file 'MemoryStream' is corrupted! Remove it and launch unity again!
[Position out of bounds! 20 > 16]
UnityEditor.AssetDatabase:OpenAsset(Int32, Int32)
UnityEditor.AssetDatabase:OpenAsset(Int32)
UnityEditor.ProjectBrowser:OpenAssetSelection(Int32[])
UnityEditor.ProjectBrowser:OpenListAreaSelection()
UnityEditor.ProjectBrowser:ListAreaItemSelectedCallback(Boolean)
UnityEditor.ObjectListArea:SetSelection(Int32[], Boolean)
UnityEditor.LocalGroup:HandleMouseWithDragging(Int32, Int32, Rect)
UnityEditor.LocalGroup:smile:rawItem(Rect, FilterResult, BuiltinResource, Boolean)
UnityEditor.LocalGroup:smile:rawInternal(Int32, Int32, Single)
UnityEditor.Group:smile:raw(Single, Vector2)
UnityEditor.ObjectListArea:HandleListArea()
UnityEditor.ObjectListArea:OnGUI(Rect, Int32)
UnityEditor.ProjectBrowser:OnGUI()
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView:Invoke(String, Object)
UnityEditor.HostView:Invoke(String)
UnityEditor.DockArea:OnGUI()

Looked up other instances where a similar error occurred for people, but it seems to be something different. It’s also really odd that it happened on the switch over to 4.5.

Tried deleting Unity and reinstalling, but didn’t have any effect.

Happens on both Macbook Pro 9,1 with latest Mavericks and PC running Windows 7 Ultimate.

The same problem and on 4.5 too. Win7 Ultimate x64.

Same issue with our project on both windows and mac after upgrading to 4.5
Will have to downgrade to 4.3 :frowning:

Unity please fix the issue ASAP!

The crashing levels had a Prefab with a Missing MonoBehavior. Removed the missing reference and it seems to be working now!

I personally was getting this error when changing Asset Serialization from ‘Mixed’ to ‘Force Text’, but it seems to be triggered by a number of things. In the end, the root cause does indeed seem to be a missing reference. So I found and used a script to find all prefabs with missing references in my project and either fixed or removed them, and the error went away.

You can find the script here: EDITOR: Want to check all prefabs in a project for an attached MonoBehaviour - Unity Engine - Unity Discussions

For some of us (like me) with a prefab with a large number of objects (and several hundred missing scripts) simply finding them with a script, and removing them manually through the UI just isn’t good enough. For anyone else in this situation, If you have your asset serialization forced to text, you can do the following:

  1. Find one of your objects with the missing monobehaviour
  2. Give it a completely unique name.
  3. Using Notepad++ or another text editor you like, open the prefab file, and search for the unique name.
  4. Copy and save somewhere else the list of component references in the gameobject.

They will look like this:

m_Component:

  • 4: {fileID: 400008}
  • 33: {fileID: 3300008}
  • 23: {fileID: 2300008}
  • 64: {fileID: 6400000}
  • 65: {fileID: 6500006}
  1. Using the unity editor, manually remove the missing monobehaviour.
  2. Ensure that the prefab / project have been saved
  3. Load the prefab file in your text editor (if you left it open, ensure it has updated)
  4. Search again for your unique name
  5. Look at the component references, compare them to the ones you saved in step 4, and determine which one is no longer present (the one with the missing reference).
  6. Do a find / replace in your text editor to replace the bad component reference with an empty string (basically removing it).

Now all objects within the prefab are free of the missing monobehaviour reference which was causing the error.

I Strongly suggest you backup the prefab first, in case something goes wrong. In our case, we just use source control.

I hope this helps people with this problem!

I started getting this recently in 5.0.2. It just happens at random on the start of the editor. Unity will crash over and over popping up new Crash Reporters each time. After a force close and re-open, Unity will have several other permanent errors relating to UnityEngine.dll (I didn’t take a screen shot of the errors to be more precise.) All monobehavior references are corrupted and basically the project is completely broken no matter how many times you restart Unity. Fortunately, deleting the Library and Obj folders in the project fixes it. After Unity rebuilds the library, all is well.

This has happened twice to me so far, once today and once yesterday. The project is fairly simple and the scene loaded at start is extremely simple. I’ve never seen this bug in 4.x.

1 Like

I had this with 5.1.2. The steps to produce it were I disabled a scene in build settings and move it to a new folder. Then I started the game and got this message.
Interesting: After restarting Unity I ran into the following error (not the first time):
UnityEditor.Networking.dll’ is in timestamps but is not known in assetdatabase…
The workaround from this thread helped to get it working again.

I just had this problem and wiping the /Temp and /Library folders resolved it.

4 Likes

This can happen occasionally when working from git repos. Advice as above always fixes it.

1 Like

We had this problem when a team member opened a Unity 5.2 project with Unity 5.0.x. Be mindful of your project vs. Unity versions!

We had to downgrade 5.2.0p1 to 5.1.3p3 because of some lingering brokenness in the 5.2 release. Hit this error and the above worked for us. (Note: on first load Unity still crashed after deleting /Temp and /Library but on second load we were back in business)

Cheers, exact same situation with downgrading due to 5.2 bugs, 2nd load after temp/library did the trick.

Haha… you guys got me again! :slight_smile: !

Updated to Unity 5.2.2f1 this morning hoping that some of the suck was gone… and sure enough it wasn’t! Had to downgrade back to 5.1.3p3 again and revisit this forum post for the third time to remember what it was we do to fix this error when downgrading back to a usable release.

5.3 and it’s still doing it, 3 times in one week and having to rebuild the two folders in a big project takes some time …

Unity really need to sort this out …

Then when it’s rebuilt I then have to switch platforms because it defaults to PC and I’m using iOS …

Such a time waster, when I don’t get much time on it anyway :frowning:

Same here 5.3.1
The file ‘MemoryStream’ is corrupted! Remove it and launch unity again!
[Position out of bounds!]

(Filename: C:/buildslave/unity/build/Runtime/Serialize/SerializationCaching/CachedReader.cpp Line: 217)

It’s not from a broken prefab.Can’t find the source of the problem…

Edit: Found it! It was a missing prefab in a scene object.
Edit 2: Meh…It’s not from a missing prefab…In my case crashes when changing Editor->UnityRemote->Device-> iPhone4s. Then when restarting Unity and hitting Play it crashes and i have to delete the Library and Temp. Now Unity Remote became unusable…

1 Like

Fixed (for git): Rather than deleting the Library folder, go into your git UI (I use SourceTree) and stage the current Library folder. Once it’s staged, right click and select “Reset To Commit”. Open Unity and run your game.

1 Like

But this does not comply with Unity’s recommendation to ignore the Library folder. Thus it blows up your repositories, s. the docs about Unity - Mastering Project Folder Structure - Version Control System:

Instead of deleting I suggest the DLL trick as mentioned above, s.this forum post

1 Like

Also worked for me i.e. changed to Editor->UnityRemote->Device->None

Confirmed with changed to Editor->UnityRemote->Device->None->Exit Unity (To save this config)->reopen->Fixed on Unity 5.3.1p3

4 Likes