LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fatal internal error: "memory.cpp" line 638

I have created a dll (C++) from a labview vi (7.1.1 WinXP) that does order analysis. However when i try to use this dll i keep getting this memory error. I believe i am allocating memory correctly (i.e. i am using DSNewHandle and DSSetHandleSize etc).

I have seen other messages that claim that this error is caused by the "Type cast" function in LV. I don't use the "Type cast" function in my vi specifically (attached) however it is in some of the NI vi's that i use for order analysis (e.g. New Gabor Refnum.vi). The actual Labview code (i.e. the Labview vi that i used to create the dll) does not give me this error when i run it. It only occurs when i run the dll.

Any help would be appreciated.

Thank you
0 Kudos
Message 1 of 7
(3,615 Views)
Forgot to mention that it does not create a failure when it happens. I have attached the build file that i used to create the dll and i have pasted my c++ code to verify that i am allocating memory correctly. Thanks


long PulsesPerRev=0, *pDataSize, ErrorCode=0, Size=0, Speedlen, Timelen;
double SampleRate=0, Value, MinOrder=0, MaxOrder=0, OrderResolution=0;
double RpmOffset=0, RpmMult=0, QntOffset=0, QntMult=0, OrdOffset=0, OrdMult=0;

float VibValue, TachValue, SpeedProfileRPM, SpeedProfileTime;

int32 i=0, j=0, k=0;

unsigned short int iWindowType, iActWinType = 0;
int iInstance, iWindowLength, iActWinLen = 0, NumofSamples=80000, nrows =2000, ncols = 2000;

TD1Hdl HdlData, HdlTach;
TD2 InputWinInfo, ActualWinInfo;
TD3 OrderRange;
TD4Hdl HdlSpecMap; //Spec Map (intensity plot data)
TD5Hdl HdlSpeed, HdlTime;
TD6 RpmScale, OrdScale, QntInfo;

// Set values
InputWinInfo.windowLength = iWindowLength;
InputWinInfo.windowType = iWindowType;
// Set values
ActualWinInfo.windowLength = iActWinLen;
ActualWinInfo.windowType = iActWinType;

// Set values
OrderRange.MinOrder = MinOrder;
OrderRange.MaxOrder = MaxOrder;
OrderRange.Resolution = OrderResolution;

OrdScale.multiplier = OrdMult;
OrdScale.offset = OrdOffset;
RpmScale.multiplier = RpmMult;
RpmScale.offset = RpmOffset;
QntInfo.multiplier = QntMult;
QntInfo.offset = QntOffset;

// Allocate memory for spectral Map
HdlSpecMap = (TD4Hdl) DSNewHandle(sizeof(TD4Hdl));
error = DSSetHandleSize(HdlSpecMap, sizeof(long)*2 + nrows*ncols*sizeof(double) );

if (error != mFullErr && error != mZoneErr)
{
(*HdlSpecMap)->dimSizes[0] = nrows;
(*HdlSpecMap)->dimSizes[1] = ncols;
}
else {
AfxMessageBox("Unable to allocate memory");
}

// Allocate memory for speed profile arrays
HdlData = (TD1Hdl) DSNewHandle(sizeof(TD1Hdl));
error = DSSetHandleSize(HdlData, sizeof(long) + NumofSamples*sizeof(double) );

HdlTach = (TD1Hdl) DSNewHandle(sizeof(TD1Hdl));
error = DSSetHandleSize(HdlTach, sizeof(long) + NumofSamples*sizeof(double) );

Speedlen = 5000;
Timelen = 5000;
// Allocate memory for Vibration Data and Tach Data
HdlTime = (TD5Hdl) DSNewHandle(sizeof(TD5Hdl));
error = DSSetHandleSize(HdlTime, sizeof(long) + Timelen*sizeof(double) );

HdlSpeed = (TD5Hdl) DSNewHandle(sizeof(TD5Hdl));
error = DSSetHandleSize(HdlSpeed, sizeof(long) + Speedlen*sizeof(double) );

// Alocate memory for data size
pDataSize = (long *) DSNewPtr(sizeof(long));

// Read in Data from file
FILE *stream;
char line[100];

stream=fopen( "C:\\OrderAnalysis.txt", "r" );

while (fgets( line, 100, stream ) != NULL)
{
sscanf( line, "%f %f",&VibValue, &TachValue);
(*HdlTach)->elt[i] = TachValue;
(*HdlData)->elt[i] = VibValue;
i++;
}
fclose(stream);

(*HdlTach)->dimSize = i;
(*HdlData)->dimSize = i;

OrderAnalysis(&HdlData, &HdlTach,
&InputWinInfo, SampleRate, PulsesPerRev,
&OrderRange, &ActualWinInfo, &HdlSpecMap, &HdlSpeed,
&HdlTime, &RpmScale, &OrdScale,
&QntInfo, pDataSize);
0 Kudos
Message 2 of 7
(3,609 Views)
Okay forgot the header file
0 Kudos
Message 3 of 7
(3,609 Views)
Hello wewe,

I think this error might be related to a known issue with type-casting. But to isolate it to this, could you run the code without the call to the DLL you created? I.e. create some simulated data of what you would expect to have returned by this DLL call and pass it along to simulate the DLL call (and not actually make the call). Please let me know what comes of this,


Travis M
Applications Engineer
National Instruments
Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 4 of 7
(3,576 Views)
Please disregard that last post.....
Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 5 of 7
(3,570 Views)
Hello again,

There is an issue with type-casting, though because your LabVIEW code runs fine standalone I am almost certain that this is not the issue here. In addition, the issue with type-casting relates to making repeated calls to the same instance of a type-cast VI (such as a type-cast VI in a loop). I do not see any of these calls in your LabVIEW code.

I suspect the culprit here is with the way you are passing in data (arrays in particular) to the DLL. There might be instances in your code where you are sending in an array that is smaller than is expected by LabVIEW (which would cause a memory access fault). I would try to simplify your LabVIEW code to only take one or two parameters, and keep adding VIs (and inputs) until you have narrowed which parameter might be giving you problems. Let us know how this goes...

Travis M
Applications Engineer
National Instruments
Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 6 of 7
(3,569 Views)
One more resource that might help here: http://zone.ni.com/devzone/conceptd.nsf/webmain/7d6a20fe02edbf318625690700704cf3#5 . You might also want to consider removing these calls passing data by handle, and passing by pointer to simplify calls.
Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 7 of 7
(3,537 Views)