Warning !!!
Scilab has found a critical error (EXCEPTION_ACCESS_VIOLATION)
with "scicosim" function.
Save your data and restart Scilab.
The function I use is very simple, I build it with debug purposes:
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "scicos_block4.h"
struct emso_str {
char *u_name;
char *y_name;
int *nU;
int *nY;
} ;
void print_str(emso_str * PWork);
extern "C" _declspec(dllexport) void test(scicos_block *block,int
flag)
{ printf("flag: %d\n", flag);
if (flag == 4) { /* initialization */
emso_str *PWork;
printf("Started initialization\n");
if ((*block->work= (emso_str*) scicos_malloc(sizeof(emso_str)))==
NULL ) {
set_block_error(-16);
return;
}
PWork = (emso_str*) block->work;
PWork->u_name = new char [block->insz[0]];
PWork->u_name = "in";
PWork->y_name = new char [block->outsz[0]];
PWork->y_name = "ou";
int *uu = new int;
int *yy = new int;
uu[0] = block->insz[0];
yy[0] = block->outsz[0];
PWork->nU = uu;
PWork->nY = yy;
}
else if(flag == 1) { /* output computation*/
printf("Started output computation\n");
emso_str *PWork= (emso_str*) block->work;
SCSREAL_COP *ptr_in;
SCSREAL_COP *ptr_out;
ptr_in = (SCSREAL_COP *)block->inptr[0];
ptr_out = (SCSREAL_COP *)block->outptr[0];
ptr_out[0] = 2* get_scicos_time()*ptr_in[0];
ptr_out[1] = 2* get_scicos_time()*ptr_in[1];
print_str(PWork);
} else if (flag == 5) { /* ending */
emso_str *PWork= (emso_str*) block->work;
delete PWork->nU;
delete PWork->nY;
delete [] PWork->u_name;
delete [] PWork->y_name;
scicos_free(PWork);
}
}
void print_str(emso_str * PWork){
printf("inside print_str\n");
printf("NU: %d\n", PWork->nU[0]);
printf("NY: %d\n", PWork->nY[0]);
printf("%s\n", PWork->u_name);
printf("%s\n",PWork->y_name);
}
#ifdef __cplusplus
}; //extern "C"
#endif
My scicos diagram is like this:
Constant block ->|
| ->|Generic Block| ->Scope
Constant block-> |
(mux)
And my generic block parameters are like this:
Simulate function: test
Func. Type:4
In port sizes [-1,-2]
Out port sizes [-1,-2]
In port type 1
Out port type 1
all other parameters are default
I found it very strange since I suppose to have deleted all allocated
objects, maybe I'm missing something.
Thanks
Hello again
After take a deeper look at the output messages I found that my
structure created for passing extra arguments is being corrupted right
after the initialization flag. Anyone can tell me if it's a bug?
Thanks
Hello,
Normally what Scicos does with work is keeping its address;
scicos_malloc
is just malloc. Since you do the allocations, I don't see how Scicos
can corrupt
the structure unless something has been changed in Scilab 5 version of
Scicos.
Have you tried your example in the latest version of Scicos, scicos
4.2.1 distributed
with scilabgtk. If it does not work there, just send me the diagram, I
take a look.
Cheers
Ramine
Hello Ramine
I tried the same C program in scilab 5.0.2 in linux. The pointers does
not became corrupt but there was a problem reported as "cross variable
size checking 1" and the simulation does not go on.
I downloaded the gtk version and since I'm linking outside scilab I
would like to know where are the scilab and scicos libs (or .so) in
linux, I couldn't find them.
Thanks
Hello Ramine
I tried with scil ab 4.2 gtk for windows and got the same problem, is
it ok to send you the diagram by e-mail?
Thanks again
Sure no problem. Send me the .cos file and whatever else I need to make
it run (I suppose it is just a C code).
Ramine
Ramine
I've already sent you the e-mails, did you received them? I've been
receiving delivery failure notification, are there another e-mail to
send you the files?
EdsonCV
Non I have not received it. I don't have any particular filter simply
make sure the file you are sending is less than 2 megs.
Ramine
Ramine
Even a common e-mail sent to you 11-oct returned. I'll try to send
you from another address: edsoncv at vrtech dot com dot br
Regards
After some talk with the developers I found my problem, in fact 2
of them:
I was creating a struture
if ((*block->work= (e_str*) scicos_malloc(sizeof(e_str)))== NULL ) {
set_block_error(-16);
return;
}
and casting it this way:
PWork = (e_str*) block->work;
and the right is:
PWork = (e_str*) * block->work;
also, I was suggested to copy a char this way:
(void)strncpy(PWork->u_name, "in", sizeof(PWork->u_name));
instead of
PWork2->u_name = new char [2];
PWork2->u_name = "in";
where PWork->uname is a member of a structure allocated this way:
struct e_str {
char u_name[3];
} ;
and PWork2 was:
struct e_str {
char *u_name;
} ;
EdsonCV