Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong read from dynamic array #2112

Open
NickSZev opened this issue Oct 24, 2021 · 1 comment
Open

wrong read from dynamic array #2112

NickSZev opened this issue Oct 24, 2021 · 1 comment

Comments

@NickSZev
Copy link

NickSZev commented Oct 24, 2021

I'm trying to write node for delay of row of numbers, which enter the input sequentially.
Row of nombers is random of 1-5.

in line 37 the value nomber 'i' is output from the array.

But when nValue=5, i=6, Arduino Uno outputs '60'. Wherein A[5] not equal 60.

`node {
unsigned int i;
int a;
int *A;

int counter(unsigned int index, unsigned int nValue) {
    if (index > (nValue)) {
        return 1;
    }
    else {
        return index=index+1;
    }
}

void init()
{
A = new int[a];
}

void evaluate(Context ctx) {

if (isSettingUp()) {
// This run once
int nValue = getValue<input_N>(ctx);
a = nValue + 1;
i = 1;
init(); }

if (isInputDirty<input_UPD>(ctx)) {

   int inValue = getValue<input_IN>(ctx);
   A[i] = inValue;
   int nValue = getValue<input_N>(ctx);
   i = counter(i, nValue);
 
 if(!isInputDirty<input_UPD>(ctx));

}
emitValue<output_OUT1>(ctx, A[i]);
emitValue<output_OUT2>(ctx, A[5]); //diagnotstic data
}
}
data-delay.zip
`

@NickSZev
Copy link
Author

Found a solution: the array is increased by 1 element. I don't use the last element of the array, but now the output is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant