本机插件空异常 OSX
Native Plugin Null Exception OSX
我已经在 Unity 论坛上交叉发布了这个;如果这违反行为,我们深表歉意。
大家好
当我尝试通过插件从 Unity 在 C++ 中使用 std::map 时,我遇到了崩溃。
我没有将地图的内容从插件传递给 Unity;我只是调用成员函数,例如 find() 函数(我的应用程序崩溃的地方)
当我将我的插件加载到 C++ 控制台应用程序时代码执行正常,但它在 Unity 中崩溃。
我怀疑存在 marshalling/memory 分配问题,Unity 不允许我分配某种类型的内存
附件是 Player.log 输出以及调用 Unity 脚本和被调用方 C++ 代码。
任何帮助将不胜感激。
此致
兰科电话
调用 C# 代码:
public string filename; // The name of the audio file this behaviour corresponds to
[DllImport ("Unity-Audio-Plugin")]
private static extern void addSoundToRendererBank(string filename);
[DllImport ("Unity-Audio-Plugin")]
private static extern void addSoundToRendererBankAtPosition(string filename, float xPos, float zPos);
[DllImport ("Unity-Audio-Plugin")]
private static extern bool setSoundWithNameToPosition (string filename, float xPos, float zPos);
[DllImport ("Unity-Audio-Plugin")]
private static extern bool deactivateSoundInRendererBank (string filename);
// Use this for initialization
public int incr;
void Start () {
incr = 1;
addSoundToRendererBank (filename);
InvokeRepeating ("moveMe", 0, 0.3F);
}
.....
被调用者 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;
.......
控制台输出:
.....
The contents of the sourceIDMap:
I'm about to die.... :-(
Receiving unhandled NULL exception
Obtained 27 stack frames.
#0 0x00000111a00b91 in std::__1::__tree_iterator, std::__1::allocator >, int>, std::__1::__tree_node, std::__1::allocator >, int>, void*>*, long> std::__1::__tree, std::__1::allocator >, int>, std::__1::__map_value_compare, std::__1::allocator >, std::__1::__value_type, std::__1::allocator >, int>, std::__1::less, std::__1::allocator > >, true>, std::__1::allocator, std::__1::allocator >, int> > >::find, std::__1::allocator > >(std::__1::basic_string, std::__1::allocator > const&)
#1 0x000001119fdb21 in
uap::SoundBank::getIDForName(std::__1::basic_string, std::__1::allocator >&)
#2 0x00000111a06891 in addSoundToRendererBank
......
我已经在 Unity 论坛上交叉发布了这个;如果这违反行为,我们深表歉意。
大家好
当我尝试通过插件从 Unity 在 C++ 中使用 std::map 时,我遇到了崩溃。 我没有将地图的内容从插件传递给 Unity;我只是调用成员函数,例如 find() 函数(我的应用程序崩溃的地方)
当我将我的插件加载到 C++ 控制台应用程序时代码执行正常,但它在 Unity 中崩溃。 我怀疑存在 marshalling/memory 分配问题,Unity 不允许我分配某种类型的内存
附件是 Player.log 输出以及调用 Unity 脚本和被调用方 C++ 代码。 任何帮助将不胜感激。
此致
兰科电话
调用 C# 代码:
public string filename; // The name of the audio file this behaviour corresponds to
[DllImport ("Unity-Audio-Plugin")]
private static extern void addSoundToRendererBank(string filename);
[DllImport ("Unity-Audio-Plugin")]
private static extern void addSoundToRendererBankAtPosition(string filename, float xPos, float zPos);
[DllImport ("Unity-Audio-Plugin")]
private static extern bool setSoundWithNameToPosition (string filename, float xPos, float zPos);
[DllImport ("Unity-Audio-Plugin")]
private static extern bool deactivateSoundInRendererBank (string filename);
// Use this for initialization
public int incr;
void Start () {
incr = 1;
addSoundToRendererBank (filename);
InvokeRepeating ("moveMe", 0, 0.3F);
}
.....
被调用者 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;
.......
控制台输出:
.....
The contents of the sourceIDMap:
I'm about to die.... :-(
Receiving unhandled NULL exception
Obtained 27 stack frames.
#0 0x00000111a00b91 in std::__1::__tree_iterator, std::__1::allocator >, int>, std::__1::__tree_node, std::__1::allocator >, int>, void*>*, long> std::__1::__tree, std::__1::allocator >, int>, std::__1::__map_value_compare, std::__1::allocator >, std::__1::__value_type, std::__1::allocator >, int>, std::__1::less, std::__1::allocator > >, true>, std::__1::allocator, std::__1::allocator >, int> > >::find, std::__1::allocator > >(std::__1::basic_string, std::__1::allocator > const&)
#1 0x000001119fdb21 in
uap::SoundBank::getIDForName(std::__1::basic_string, std::__1::allocator >&)
#2 0x00000111a06891 in addSoundToRendererBank
......