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];

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

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

    其中使用了该项目.NET的Async Socket代码.后来不知道什么时候这个奇怪的错误的出现: CompareBaseObjectsInternal can only be called from ...

  2. [原]openstack-kilo--issue(十九) ImportError: Could not import settings 'openstack_dashboard.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named main

    查看此问题的时候请先查看 这个问题包含在(十)中,此篇只是从(十)中分离出来 openstack-kilo--issue(十)ERROR: openstack Unable to establish ...

  3. [java] [error] java.lang.OutOfMemoryError: unable to create new native thread

    前言 最近公司的服务器出现了oom的报错,经过一番排查,终于找到了原因.写下这篇博客是为了记录下查找的过程,也是为了帮助那些跟我门遇到的情况相同的人可以更快的寻找到答案. 环境 系统:linux(ce ...

  4. Unity 中 使用c#线程

    使用条件   天下没有免费的午餐,在我使用unity的那一刻,我就感觉到不自在,因为开源所以不知道底层实现,如果只是简单的做点简单游戏,那就无所谓的了,但真正用到实际地方的时候,就会发现一个挨着一个坑 ...

  5. SFTP &amp; FTP Upload

    简述 >> FTP: 1. Install FTP service on Linux(Red Hat) as root user    [root]# yum install ftp 2. ...

  6. CompletableFuture的使用例子

    1. CompletableFuture的介绍 在Java8时被引入,在包java.util.concurrent下,是Java多线程编程中的一个类,扩展了Future中很多功能,Completabl ...

  7. 【Linux】关于Linux的系统编程总结

    作者:李春港 出处:https://www.cnblogs.com/lcgbk/p/14673383.html 目录 系统编程 (一)进程 1.进程的概念 2.进程函数接口 (1)fork()在进程内 ...

  8. error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用

    MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 Debug ...

  9. MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC (转)

    一.问题描述 我所使用的编程环境:VS2010 出现的问题如下: MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号_WinMain@16,该符号在函数 _ ...

随机推荐

  1. Javascript技巧之不要用for in语句对数组进行遍历

    一,为什么不要用for in语句 jqModal这个jquery插件估计很多人都使用过,在jqModal源码内部,有一个函数为hs,其中有个嵌套循环如下, for(var i in {jqmShow: ...

  2. ubantu下NiFi单节点安装部署

    第一步,首先下载安装包:http://nifi.apache.org/download.html,博主下载的是1.4.0版本,直接下载的是编译后的文件. 第二步:将压缩包上传到服务器相应目录下,并且解 ...

  3. 使用Aliyun Docker 容器镜像/注册表服务

    1.前往阿里云容器镜像服务创建相关资源. 2.登录你的仓库,账户名+公共地址 docker login --username=xxxxxxxxx@aliyun.com registry.cn-hang ...

  4. rsync文件备份同步

    1.rsync有两种认证协议: ssh认证协议 rsync server端不需要启动daemon进程,所以不用配置/etc/rsyncd.conf,只需要获取远程host的用户名密码 例: rsync ...

  5. 关于百分比宽高div居中并垂直居中问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. (转)50 个 jQuery 小技巧

    1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ajaxSettings:{ contentType:"application/x-w ...

  7. Types in Javascript(jQuery)

    String: 空字符串等于Boolean的false; htmlString: 包括起始tag和结束tag的字符串,代表html代码: Number:双精度64位,跟string一样属于immuta ...

  8. 【转载】Java实现word转pdf

    最近遇到一个项目需要把word转成pdf,GOOGLE了一下网上的方案有很多,比如虚拟打印.给word装扩展插件等,这些方案都依赖于ms word程序,在java代码中也得使用诸如jacob或jcom ...

  9. opengl渲染时画面抖动

    渲一个大尺寸模型的时候模型的细节部分一直在闪烁.尝试: 1. 纹理用mipmap,失败. 2. 开启msaa,失败. 3. 相机近时不闪,越远闪的越厉害,怀疑是深度争夺,就把远裁剪平面调大,失败. - ...

  10. MFC多标签页对话框

    原文链接(有修改):http://blog.sina.com.cn/s/blog_6a1cdb3f0101llcw.html 1.新建一个MFC工程 取名PageSheet,选择Dialog base ...