Unity3d中调用C++写的Kinect手势的dll,打包运行报错!

_Tiny 2014-05-08 12:27:45

用C++写了个Kinect手势的dll给unity用,脚本是用C#写的,点Play运行没有问题,打包运行exe报错!求大神现身帮忙看看是什么原因哪,先跪谢了。。。。

error.log如下:

Unity Player [version: Unity 4.3.4f1_e444f76e01cd]

KinectPluginForUnity.dll caused an Access Violation (0xc0000005)
in module KinectPluginForUnity.dll at 001b:6840117c.

Error occurred at 2014-05-07_155058.
C:\Users\Administrator\Documents\Unity Project\ModelView\ModelView.exe, run by Administrator.
28% memory in use.
3540 MB physical memory [2517 MB free].
0 MB paging file [0 MB free].
2048 MB user address space [1762 MB free].
Read from location 00000000 caused an access violation.

Context:
EDI: 0x7682e918 ESI: 0x00000000 EAX: 0x00000000
EBX: 0x03a1e5e8 ECX: 0x7ffdf000 EDX: 0x00000006
EIP: 0x6840117c EBP: 0x0014f138 SegCs: 0x0000001b
EFlags: 0x00010246 ESP: 0x0014f104 SegSs: 0x00000023

Bytes at CS:EIP:
8b 10 50 8b 42 44 ff d0 a1 e4 36 40 68 8b 08 8b

Stack:
0x0014f104: 0014f30c 0a40e4e0 03a39871 0014f138 ......@.q...8...
..............................................
0x0014fcd4:

Module 1
C:\Users\Administrator\Documents\Unity Project\ModelView\ModelView.exe
Image Base: 0x01340000 Image Size: 0x00b65000
File Size: 11288064 File Time: 2014-01-24_062148
Version:
Company:
Product:
FileDesc:
FileVer: 4.3.4.31067
ProdVer: 4.3.4.31067

Module 2
C:\Windows\system32\xinput1_3.dll
Image Base: 0x00400000 Image Size: 0x00016000
File Size: 81768 File Time: 2007-04-04_185342
Version:
Company: Microsoft Corporation
Product: Microsoft? DirectX for Windows?
FileDesc: Microsoft Common Controller API
FileVer: 9.18.944.0
ProdVer: 9.18.944.
。。。。。。此处略去好多
Module 77
C:\Windows\system32\NSI.dll
Image Base: 0x773f0000 Image Size: 0x00006000
File Size: 8704 File Time: 2009-07-14_091612
Version:
Company: Microsoft Corporation
Product: Microsoft? Windows? Operating System
FileDesc: NSI User-mode interface DLL
FileVer: 6.1.7600.16385
ProdVer: 6.1.7600.16385


== [end of error.log] ==




output_log如下:
Initialize engine version: 4.3.4f1 (e444f76e01cd)
GfxDevice: creating device client; threaded=1
Direct3D:
Version: Direct3D 9.0c [nvd3dum.dll 9.18.13.3523]
Renderer: NVIDIA GeForce GTX 660
Vendor: NVIDIA
VRAM: 1989 MB (via DXGI)
Caps: Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=0 INTZ=1 RAWZ=0 NULL=1 RESZ=0 SlowINTZ=0
Begin MonoManager ReloadAssembly
Platform assembly: C:\Users\Administrator\Documents\Unity Project\ModelView\ModelView_Data\Managed\UnityEngine.dll (this message is harmless)
Loading C:\Users\Administrator\Documents\Unity Project\ModelView\ModelView_Data\Managed\UnityEngine.dll into Unity Child Domain
。。。。。。此处略去好多
C:\Windows\system32\dbghelp.dll:dbghelp.dll (68810000), size: 962560 (result: 0), SymType: '-exported-', PDB: 'C:\Windows\system32\dbghelp.dll', fileVersion: 6.1.7601.17514
C:\Windows\system32\SspiCli.dll:SspiCli.dll (75180000), size: 110592 (result: 0), SymType: '-exported-', PDB: 'C:\Windows\system32\SspiCli.dll', fileVersion: 6.1.7601.18270

========== OUTPUTING STACK TRACE ==================

(0x6840117C) (KinectPluginForUnity): (filename not available): (function-name not available) + 0x0
。。。。。。此处略去好多
(0x7682EE1C) (kernel32): (filename not available): BaseThreadInitThunk + 0x12
(0x772E37EB) (ntdll): (filename not available): RtlInitializeExceptionChain + 0xef
(0x772E37BE) (ntdll): (filename not available): RtlInitializeExceptionChain + 0xc2

========== END OF STACKTRACE ===========

**** Crash! ****
...全文
436 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
经过各种测试表明应该是Nui_Init函数初始化Kinect失败返回的HRESULT 谢谢几位帮忙 结贴了
xian_wwq 2014-05-08
  • 打赏
  • 举报
回复
C#可以和c联调的,项目属性-调试-启用非托管代码调试,可以跟一下,传进去的参数是否正确。 还有那个init函数的参数,把bool改为int,再试试
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
从log信息(0xc0000005)判断应该是Nui_Init函数初始化Kinect失败返回的HRESULT
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
引用 5 楼 xian_wwq 的回复:
是所有的函数调用都有问题,还是其中一部分? 贴个以前做过的转换样例,可以参考下 [DllImport("mydll", EntryPoint = "MyFunction", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
经测试判断是dll中所有函数都调用失败~ 但是在Unity3d中,Play运行没有问题,打包之后资源文件中也有dll,运行打包之后的exe,执行调用dll中方法的一些操作都无效了,这会是什么原因呢? Assets目录如下:MyModel,MyScript,Plugins,Scene。打包之后,资源自动会放到和生成的exe文件同目录下的ProjectName_Data目录,在这个目录下有Managed,Mono,Plugins(dll存在),Resources4个文件夹,mainData,PlayerConnectionConfigFile,sharedassets0.assets3个文件。
xian_wwq 2014-05-08
  • 打赏
  • 举报
回复
是所有的函数调用都有问题,还是其中一部分? 贴个以前做过的转换样例,可以参考下 [DllImport("mydll", EntryPoint = "MyFunction", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
引用 2 楼 xian_wwq 的回复:
Access Violation可能相关: 1. stdcall cdecl fastcall等函数调用约定不匹配。 2. dllimport转换时,C#和C++对应的类型不匹配 实在不行把api贴出来看看
C#脚本 //NUI Context Management [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern bool NuiContextInit(bool twoPlayer); [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern void NuiUpdate(); [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern void NuiContextUnInit(); //Get Methods [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern void GetSkeletonTransform(int player, int joint, ref SkeletonTransform trans); [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern IntPtr GetTextureImage(ref int size); [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern IntPtr GetDepthImage(ref int size); [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern void GetCameraAngle(ref float angle); //Set Methods [DllImport("/Assets/Plugins/KinectPluginForUnity.dll")] public static extern bool SetCameraAngle(int angle);
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
引用 2 楼 xian_wwq 的回复:
Access Violation可能相关: 1. stdcall cdecl fastcall等函数调用约定不匹配。 2. dllimport转换时,C#和C++对应的类型不匹配 实在不行把api贴出来看看
#ifndef UNITYINTERFACE_API #define UNITYINTERFACE_API extern "C" __declspec(dllexport) #endif //DEFINE INTERFACE METHODS //Nui Context Management UNITYINTERFACE_API bool NuiContextInit(bool twoPlayer); UNITYINTERFACE_API void NuiUpdate(); UNITYINTERFACE_API void NuiContextUnInit(); //Get Methods UNITYINTERFACE_API void GetSkeletonTransform(int player, int joint, OUT KUVector4* SkeletonTransform); UNITYINTERFACE_API byte* GetTextureImage(OUT int* size); UNITYINTERFACE_API byte* GetDepthImage(OUT int* size); UNITYINTERFACE_API void GetCameraAngle(OUT float* angle); //Set Methods UNITYINTERFACE_API bool SetCameraAngle(int angle); 还需要cpp文件吗?
xian_wwq 2014-05-08
  • 打赏
  • 举报
回复
Access Violation可能相关: 1. stdcall cdecl fastcall等函数调用约定不匹配。 2. dllimport转换时,C#和C++对应的类型不匹配 实在不行把api贴出来看看
_Tiny 2014-05-08
  • 打赏
  • 举报
回复
大神都去那了?自己顶下。。。。。。

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧