LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

first execution ok, second execution crash!

I've programed a simple CIN in Visual C. Always, when I execute the program for the first time, every thing is fine. When I change the 'Iteration' parameter and execute the program for a second time I got an 'Access Violation' 0xC0000005. I tried to reinitialize the VI and to initialize the Array before I execute...
I think, there must be an programing error in the c source.
Thanks for any suggestions!
(I'am working with LabView 6.1)
Download All
0 Kudos
Message 1 of 3
(2,563 Views)
roman wrote:

> I've programed a simple CIN in Visual C. Always, when I execute the
> program for the first time, every thing is fine. When I change the
> 'Iteration' parameter and execute the program for a second time I got
> an 'Access Violation' 0xC0000005. I tried to reinitialize the VI and
> to initialize the Array before I execute...
> I think, there must be an programing error in the c source.
> Thanks for any suggestions!
> (I'am working with LabView 6.1)

In the loop

for(k=0;k<*Iterations;k++){
presult++;
temp += *Step;
*presult = temp;
};

you really iterate *Iterations times through the array. But you start
inside the loop to fill the element at index 1, so in fact you write one
array element byeond the end of hte array and in this way cor
rupt some
internal LabVIEW data. Next time the VI executes it stumbles over this
memory corruption and crashes.

Make the first line of that loop:

for(k=1;k<*Iterations;k++){

One more point, this function would still not behave properly if you
would pass in 0 as *Iteration as you would write beyond the array again
when you assign the StartValue to the first element in the array.

If you do it as follows this is also taken care of:

if (err = SetCINArraySize((UHandle)Array, 3, *Iterations))
return err;
(*Array)->dimSize = *Iterations;

presult = (*Array)->Numeric;

for (k = 0; k < *Iterations; k++, presult++) {
*presult = temp;
temp += *Step;
};

return noErr;

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 3
(2,563 Views)
Silly me! I have been investigating the code for quite a long time...
Thanks a lot for your help!

Roman
0 Kudos
Message 3 of 3
(2,563 Views)