Error: CompareBaseObjectsInternal can only be called from the main thread

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:


  1. public class Node : ScriptableObject
  2.  {
  3.         public int[] data;
  4.  }
  5.  
  6. List<Node> dataset;
  7. ..
  8.  
  9. // Error, this fails inside of thread
  10. Node node = dataset[i];

this works:

Code:


  1. public interface INodeData
  2.  {
  3.         int[] data { get; }    
  4.  }
  5.  
  6. public class Node : ScriptableObject, INodeData
  7.  {
  8.         public int[] data;
  9.  }
  10.  
  11. List<INodeData> dataset;
  12. ..
  13.  
  14. // this works! inside of thread
  15. INodeData node = dataset[i];
时间: 2025-01-05 20:05:03

Error: CompareBaseObjectsInternal can only be called from the main thread的相关文章

Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.

其中使用了该项目.NET的Async Socket代码.后来不知道什么时候这个奇怪的错误的出现: 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 con

Linux之线程:控制与分离

之前我一直都提到的是进程,现在多了一个线程的概念,从字面意思来看,线程应该比进程小.嘿嘿. 其实操作系统刚开始的时候,提出进程概念后,操作系统一直都是以进程作为独立运行的基本单位,然后有人感觉了,这不对呀,进程之间的中断转换太浪费了,并且用户态到核心态的切换也有点麻烦,所以在80年代中期,人们又提出了毕竟更小的独立运行的基本单位咯--线程,用来提高系统内存程序的并发执行程度.所以线程就这么出现了. 那,什么是线程呢? 其实简单来说,线程就是进程中的执行分流,从操作系统内部来说其实就是一个指令序列

SFTP &amp;amp; FTP Upload

简述 >> FTP: 1. Install FTP service on Linux(Red Hat) as root user [root]# yum install ftp 2. Configure FTP as root user a) Be clear with below properties, and configure them in the file /etc/vsftpd/vsftpd.conf as root user # Uncomment this to allow l

Unity 中 使用c#线程

       天下没有免费的午餐,在我使用unity的那一刻,我就感觉到不自在,因为开源所以不知道底层实现,如果只是简单的做点简单游戏,那就无所谓的了,但真正用到实际地方的时候,就会发现一个挨着一个坑,然后你就跟着unity做各种妥协. 注意点        如果开发中需要使用网络等等涉及到多线程的地方,就会用到c#的多线程,注意不是unity的协程,你要做的妥协参考下面(网友整理,我没去搜索)的: 1. 变量(都能指向相同的内存地址)都是共享的 2. 不是UnityEngine的API能在分线

linux多线程入门

linux下的多线程通过pthread实现,下面给个简单的例子. #include <stdio.h> #include <stdlib.h> #include <pthread.h> void* thr_fn() { printf("this is a thread, tid = %d\n", pthread_self()); printf("thread return\n"); return (void*)0; } int m

iOS线程安全问题

此文章将侧重于编写线程安全类和使用Grand Central Displatch(GCD)时的实用的技巧,设计模式,以及反模式. 线程安全 Apple的框架 首先让我们来看一下Apple的框架.一般情况下,除非提前声明,否则大多数类默认不是线程安全的.一些是我们所期望的,但是另一些却会相当有趣. 其中甚至有经验的iOS/Mac开发人员常会犯的错误是在后台线程中访问部分UIKit/AppKit.最容易犯的错误是在后台线程中对property赋值,比如图片,因为他们的内容是在后台从网络上获取的.Ap

SFTP &amp; FTP Upload

简述 >> FTP: 1. Install FTP service on Linux(Red Hat) as root user [root]# yum install ftp 2. Configure FTP as root user a) Be clear with below properties, and configure them in the file /etc/vsftpd/vsftpd.conf as root user # Uncomment this to allow l

Linux多线程实现及线程同步函数分析

在Linux中,多线程的本质仍是进程,它与进程的区别: 进程:独立地址空间,拥有PCB 线程:也有PCB,但没有独立的地址空间(共享) 线程的特点: 1,线程是轻量级进程,有PCB,创建线程使用的底层函数和进程一样,都是clone 2,从内核看进程和线程是一样的,都有各自不同的PCB 3,进程可以蜕变成线程 4,在LINUX中,线程是最小的执行单位,进程是最小的分配资源单位 查看指定线程的LWP号命令: ps -Lf pid 线程优点: 提高程序并发性 开销小 数据通信,共享数据方便 线程缺点:

MYSQL ERROR

mysql出错了以前往往靠猜.有了这张表一查就出来了.方便不少.特共享于众 1005创建表失败 1006创建数据库失败 1007数据库已存在创建数据库失败 1008数据库不存在删除数据库失败 1009不能删除数据库文件导致删除数据库失败 1010不能删除数据目录导致删除数据库失败 1011删除数据库文件失败 1012不能读取系统表中的记录 1020记录已被其他用户修改 1021硬盘剩余空间不足请加大硬盘可用空间 1022关键字重复更改记录失败 1023关闭时发生错误 1024读文件错误 1025