c语言 dll unity,c# - 在Unity,MonoBehaviour中使用DLL - 堆栈内存溢出

我有一个用C语言编写的机翼几何和流求解器代码库。我制作了一个简单的测试项目,用于调试库,C#包装器类和主项目之间的一些集成问题。 在这个测试项目中,我有一个测试脚本:

using UnityEngine;

using System;

using System.Collections.Generic;

using System.Collections;

using System.Runtime.InteropServices;

public class testScript2 : MonoBehaviour {

// external functions

[DllImport( "TestLib" )]

public static extern void makeWing( ref stripCalcStruct wing,

int n_sections, bool isSwept, double sweep );

[DllImport( "TestLib" )]

public static extern void makeComp( ref stripCalcStruct wing,

ref compNILLStruct wingComp );

[DllImport( "TestLib" )]

public static extern void NILLWingEx( ref stripCalcStruct wing,

ref compNILLStruct comp, ref outNILL results, bool simpsons );

// member variables to store computation results

public double calculation1 = 0.0;

public double calculation2 = 0.0;

public double calculation3 = 0.0;

public double calculation4 = 0.0;

public double calculation5 = 0.0;

public double calculation6 = 0.0;

// Use this for initialization

void Start () {

// this is my "main" program

// initialize some geometric parameters

int numCS = 2;

int numControlStations = 2;

int numAirfoils = 1;

int numAiCoeffs = 10;

int n_sections = 40;

// Create a StripController

StripController controller1 = new StripController(

n_sections, numCS, numControlStations, numAirfoils, numAiCoeffs );

controller1.tryStuff();

// Fill the wing geometry with a default wing from the library

makeWing( ref controller1.wing, 40, false, 0.0 );

// save a piece to see that it worked

calculation1 = controller1.wing.area;

// Fill computational state parameters with default values from the library

makeComp( ref controller1.wing, ref controller1.comp );

// save a piece to see that it worked

calculation2 = controller1.getAlphaAtIndex( 0 );

// Call the flow solver from the library

NILLWingEx( ref controller1.wing, ref controller1.comp,

ref controller1.results, false );

// save the required computation time

calculation3 = controller1.results.time;

// free pinned memory in the controller

controller1.freeStuff();

/* Try this again, but this time call the NILLWingEX function from

* within the StripController file */

StripController controller2 = new StripController(

n_sections, numCS, numControlStations, numAirfoils, numAiCoeffs );

controller2.tryStuff();

makeWing( ref controller2.wing, 40, false, 0.0 );

calculation4 = controller2.wing.area;

makeComp( ref controller2.wing, ref controller2.comp );

calculation5 = controller2.getAlphaAtIndex( 0 );

controller2.EvalNILL(); // This fails

calculation6 = controller2.results.time;

controller2.freeStuff();

}

// Update is called once per frame

void Update () {

}

void OnGUI()

{

// display our computation results on the screen

GUI.Label( new Rect( 100f, 100f, 500f, 20f ), calculation1.ToString() );

GUI.Label( new Rect( 100f, 120f, 500f, 20f ), calculation2.ToString() );

GUI.Label( new Rect( 100f, 140f, 500f, 20f ), calculation3.ToString() );

GUI.Label( new Rect( 100f, 160f, 500f, 20f ), calculation4.ToString() );

GUI.Label( new Rect( 100f, 180f, 500f, 20f ), calculation5.ToString() );

GUI.Label( new Rect( 100f, 200f, 500f, 20f ), calculation6.ToString() );

}

}

有一个包含StripController类的StripController.cs文件。 班级的最顶层看起来像这样

public class StripController

{

[DllImport( "TestLib" )]

public static extern void NILLWingEX( ref stripCalcStruc wing,

ref compNILLStruct comp, ref outNILL results, bool simpsons );

因此,它具有与其他文件相同的外部NILLWingEX定义。 EvalNILL()方法看起来像这样

public void EvalNILL()

{

NILLWingEX( ref wing, ref comp, ref results, false );

}

在测试脚本文件中,在第一个块中使用StripController并在本地调用NILLWingEX可以正常工作。 但是在第二个块中,从该文件中,我让StripController调用NILLWingEX ,我得到了EntryPointNotFoundException: NILLWingEX 。 因此,我可以从测试脚本文件中调用外部函数,但不能从其他文件中调用? 这与从MonoBehaviour继承有关吗? 这是否与将测试脚本附加到游戏对象(主摄像机)有关?

任何有助于澄清何时/何地可以在Unity中调用库函数的帮助将不胜感激。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值