Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本机插件空异常OSX_C#_C++_Macos_Unity3d - Fatal编程技术网

C# 本机插件空异常OSX

C# 本机插件空异常OSX,c#,c++,macos,unity3d,C#,C++,Macos,Unity3d,我已经在Unity论坛上交叉发布了这篇文章;如果这违反了行为准则,我会道歉 大家好 我遇到了一个崩溃,当我尝试通过插件使用一个STD::C++中的统一映射。 我没有将地图的内容从插件传递给Unity;我只是调用成员函数,比如find()函数(我的应用程序在这里崩溃) < >当我把插件加载到C++控制台应用程序中时,代码执行得很好,但是它在Unity中崩溃了。 我怀疑存在编组/内存分配问题,Unity不允许我分配某种内存 附件是Pr.Real.Load输出和调用Unity脚本和CALLY C++代

我已经在Unity论坛上交叉发布了这篇文章;如果这违反了行为准则,我会道歉

大家好

我遇到了一个崩溃,当我尝试通过插件使用一个STD::C++中的统一映射。 我没有将地图的内容从插件传递给Unity;我只是调用成员函数,比如find()函数(我的应用程序在这里崩溃)

< >当我把插件加载到C++控制台应用程序中时,代码执行得很好,但是它在Unity中崩溃了。 我怀疑存在编组/内存分配问题,Unity不允许我分配某种内存

附件是Pr.Real.Load输出和调用Unity脚本和CALLY C++代码。 任何帮助都将不胜感激

问候

兰蔻

调用C#代码:

< P> Calee C++代码:

 void addSoundToRendererBank(char *filename)
 {
     printf("Calling the addSoundToRendererBank function with %s as a filename\n", filename);
     copyStringFromManagedCaller(filename);
     std::string fileNameStr(&buffer[0]);

     int soundLoc = soundBank->getIDForName(fileNameStr);
     if (soundLoc > 0) { // Sound is already in the bank
         // If its just been deactivated, reactivate it
         std::string key(&buffer[0]);
         soundBank->activateSoundSource(key);
     }
     ...
     ...
     int SoundBank::getIDForName(std::string &filePath)
     {
          // Filepath -> sourceIDMap -> source -> ID
          std::string key(filePath);
          int location;

          std::cerr << "About to enter the try-catch block in the SoundBank::getIDForName() function using " << key << std::endl;

          // Print the current elements inside the map
          std::cerr << "The contents of the sourceIDMap:" << std::endl;
          SoundSourceMapIterator map_it;
        //        for (map_it = sourceIDMap.begin(); map_it != sourceIDMap.end(); ++map_it) {
        //            std::cerr << "Key: " << map_it->first << "\tValue: " << map_it->second << std::endl;
        //        }
          std::cerr << "I'm about to die.... :-(" << std::endl;

          // Throws randomers; using find instead
          //        try
          //        {
          //            location = sourceIDMap.at(key);
          //        }
          //        catch (const std::out_of_range& oorEx)
          //        {
          //            location = -1;
          //        }

          SoundSourceMapIterator it = sourceIDMap.find(key);
          if (it == sourceIDMap.end())
              location = -1;
          else
              location = it->second;
          .......
void addsoundtorenderbank(char*filename)
{
printf(“使用%s作为文件名调用AddSoundToRenderBank函数,\n”,文件名);
copyStringFromManagedCaller(文件名);
std::string fileNameStr(&buffer[0]);
int soundLoc=soundBank->getIDForName(fileNameStr);
如果(soundLoc>0){//Sound已在银行中
//如果它刚刚被停用,请重新激活它
std::字符串键(&缓冲区[0]);
声音库->激活声音源(键);
}
...
...
int SoundBank::getIDForName(std::string和filePath)
{
//文件路径->源ID映射->源->ID
std::字符串键(filePath);
int定位;

我已经解决了这个问题

这些函数的作用是什么?
copyStringFromManagedCaller(filename);
std::string fileNameStr(&buffer[0]);
为什么它们通过一个来源未知的缓冲区变量连接?我希望它有一个返回值。我添加了这些函数,因为我认为错误是在编组字符串。copyStringFromManagedCaller(filename)将filename变量复制到静态char[]。然后我获取缓冲区第一个元素的地址,以便在没有常量限定的情况下将char*抓取到缓冲区。没有此缓冲区,代码仍然崩溃(即仅通过传递原始filename char数组)@nvoigt有帮助吗?听起来很可疑,为什么不使用本地缓冲区并返回字符串呢?
 void addSoundToRendererBank(char *filename)
 {
     printf("Calling the addSoundToRendererBank function with %s as a filename\n", filename);
     copyStringFromManagedCaller(filename);
     std::string fileNameStr(&buffer[0]);

     int soundLoc = soundBank->getIDForName(fileNameStr);
     if (soundLoc > 0) { // Sound is already in the bank
         // If its just been deactivated, reactivate it
         std::string key(&buffer[0]);
         soundBank->activateSoundSource(key);
     }
     ...
     ...
     int SoundBank::getIDForName(std::string &filePath)
     {
          // Filepath -> sourceIDMap -> source -> ID
          std::string key(filePath);
          int location;

          std::cerr << "About to enter the try-catch block in the SoundBank::getIDForName() function using " << key << std::endl;

          // Print the current elements inside the map
          std::cerr << "The contents of the sourceIDMap:" << std::endl;
          SoundSourceMapIterator map_it;
        //        for (map_it = sourceIDMap.begin(); map_it != sourceIDMap.end(); ++map_it) {
        //            std::cerr << "Key: " << map_it->first << "\tValue: " << map_it->second << std::endl;
        //        }
          std::cerr << "I'm about to die.... :-(" << std::endl;

          // Throws randomers; using find instead
          //        try
          //        {
          //            location = sourceIDMap.at(key);
          //        }
          //        catch (const std::out_of_range& oorEx)
          //        {
          //            location = -1;
          //        }

          SoundSourceMapIterator it = sourceIDMap.find(key);
          if (it == sourceIDMap.end())
              location = -1;
          else
              location = it->second;
          .......