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:
this works:
Code:
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];
相关文章推荐
- Error: CompareBaseObjectsInternal can only be called from the main thread
- Unity3d报奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- Unity3d报奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- unity DestroyBuffer can only be called from the main thread
- unity报错get_streamingAssetsPath can only be called from the main thread. Constructors and field initi
- unity报“GetLocalizedString can only be called from the main thread.”错误。
- "may only be called from the main thread"
- -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.【创建键盘监听事件,然后操作键盘(弹出、收回),结果在运行程序时出现如下错误(如有知道解决办法的朋友请留言探讨!)】
- calledfromwrongthreadexception only the original that created a view hierarchy can touch its views
- you are calling a UIKit method that can only be invoked from the UI thread.
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
- CalledFromWrongThreadException:Only the original thread that created a view hierarchy can touch its
- Python SQLite3的问题sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in th
- studio 3.0 自定义控件报错TintTypedArray can only be called from within the same library group
- Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be
- Exception in thread "main" java.sql.SQLException: Connections could not be acquired from the underly
- How can I protect derived classes from breaking when I change the internal parts of the base class?
- android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
- CalledFromWrongThreadException: Only the original thread that created a view