- Home /
Unity crushes while running dll functions(log+code)
http://rghost.ru/79NkzRx7p - here is log file
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
public class Grapher2 : MonoBehaviour {
[DllImport ("1" )]
private static extern void Create_polygon( int aa,int log_, int N_x, int N_y, double N_t);
[DllImport ("1" )]
private static extern void Get_partition ();
[DllImport ("1" )]
private static extern double Get_length();
[DllImport ("1" )]
private static extern double Get_height ();
[DllImport ("1" )]
private static extern int Get_x ();
[DllImport ("1" )]
private static extern int Get_y ();
[DllImport ("1" )]
private unsafe static extern void Solve(double time_start,int NT,double * Temp);
[DllImport ("1" )]
private static extern double Get_Temp_By_ij( int i, int j);
[DllImport ("1" )]
private static extern double Get_Temp_By_xy( double x, double y);
//some more code here//
void Update () {
if (currentResolutionx != resolutionx ||currentResolutiony != resolutiony || points == null) {
CreatePoints();
}
if (Input.GetButton("Fire1")) {
Vector2 mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if(mouse.x<=Graph.x+1 && mouse.x>=Graph.x && mouse.y>=Graph.y && mouse.y<=Graph.y+1) {
scannedpoint = mouse;
Point.transform.position = scannedpoint;
Graph2.GetComponent<Grapher1>().scannedpoint = scannedpoint;
SPP.GetComponent<SPP>().x = ((scannedpoint.x)*xk).ToString();
SPP.GetComponent<SPP>().y = ((scannedpoint.y)*yk).ToString();
}
}
if (ExperiementOn) {
unsafe {
fixed(double* qwe = &(TT[0])){
Debug.Log("Fu 3");
time_start += SMALL_TIME_STEP * Time_steps;
Solve (time_start,Time_steps,qwe);
Debug.Log("DD 4");
Debug.Log("DD 5");
CLOCK.GetComponent<Timer> ().delta = SMALL_TIME_STEP * Time_steps;
for (int i = 0; i < points.Length; i++) {
float Temp = (float)((double)(*(qwe+i*8)));
if (Temp > 0) points [i].color = RGBfromTemp (Temp);
points [i].color = new Color(1f,1f,0f);
points [i].size = size;
}
}
}
particleSystem.SetParticles (points, points.Length);
}
}
I use unity3d in order to make a visualization for a computer experiement, which is written in C++. So i wrapped it into dll file and tried it. Some functions worked fine, some did not. The probable issue might be the following: i allocate memory for an array of doubles in c# code, then pass the pointer to c++ dll function and then try to read from it. Can't see anything wrong with it, but if i erase the part of the code responsible for that, it does not crash.
Report says my dll caused access violation, can't give more info
Solved. I was not careful when accessing memory in c# code.
Your answer
Follow this Question
Related Questions
Shared memory between c# and c++ 1 Answer
Importing C++/CLI DLL causes errors 0 Answers
Multiple Cars not working 1 Answer
How to assign a function to UnityEvent without the use of lambdas? 1 Answer
Distribute terrain in zones 3 Answers