您的位置:首页 > 移动开发 > Objective-C

Error: CompareBaseObjectsInternal can only be called from the main thread

2014-05-23 13:03 363 查看
Posted: 01:39 PM 06-17-2013

hi, we’re working on a project where we need to do some calculations on a separate thread. The data we need for the calculations is stored on a scriptable object. We use the scriptable object so that we can
serialize the data and save it as an asset file. However, when we tried to access the data from a separate thread we get the following error.

CompareBaseObjectsInternal can only be called from the main thread.

Constructors and field initializers will be executed from the loading thread when loading a scene.

Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

For our purposes we only need to read the data. One of the things that we tried to do to get around this was to use an interface. It appears that if you use an interface as a reference to the object then you’re able to access the data without getting that error.
For example

Code:
public class Node : ScriptableObject

{

public int[] data;

}

List<Node> dataset;

..

// Error, this fails inside of thread

Node node = dataset[i];


this works:

Code:
public interface INodeData

{

int[] data { get; }

}

public class Node : ScriptableObject, INodeData

{

public int[] data;

}

List<INodeData> dataset;

..

// this works! inside of thread

INodeData node = dataset[i];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐