SDL_Mixer not working on part of the code - c

I've just a strange problem. I'm looking to put sounds in my game. It's a game with two phases. One of rpg and one of fight. In rpg you can launch a fight when you walk on a monster. In my code i use 3 times SDL_mixer to play music (in the menu and in the rpg and in the fight). It works in the first two cases, but when i launch a fight there is no music. The music is loaded, and Mix_playingMusic returns true, but I can't hear any music when a fight is launched. I use the same music than in the rpg and menu. The code about SDL_Mixer is the same everywhere.
Part of the code of the fight :
{
SDL_Event events;
Mix_Music *fightMusic;
enum actual_player actual = PLAYER;
int go = 1;
int action;
int monsterId = 0;
Uint32 t = SDL_GetTicks(), nt;
fightMusic = Mix_LoadMUS("data/Music/rpg.mp3"); // we loading the music
if(fightMusic == NULL){
printf("error loading fightMusic\n");
}
Mix_VolumeMusic(MIX_MAX_VOLUME);
if(Mix_PlayMusic(fightMusic, -1)<0){
printf("error playing fightMusic \n");
}
if (Mix_PlayingMusic() ){
printf("Music it's playing \n");
}
while(go){
if(isFinished(fightSdl->fight))
go = 0;
nt = SDL_GetTicks();
while (SDL_PollEvent(&events)){
action = inputKeyboard(events);
if(action == QUIT){
return -1;
go = 0;
}
if(action == -2){
clearBufferGame(fightSdl->buffer, CHARACTER);
}
if(actual == PLAYER) {
switch(action){
case MOVE_DOWNWARD:
addActionToBufferGame(fightSdl->buffer, DOWN);
break;
case MOVE_UPWARD:
addActionToBufferGame(fightSdl->buffer, UP);
break;
case MOVE_LEFT:
addActionToBufferGame(fightSdl->buffer, LEFT);
break;
case MOVE_RIGHT:
addActionToBufferGame(fightSdl->buffer, RIGHT);
break;
case ATTACK_1:
actionAttackSdl(fightSdl, ATTACK_1);
break;
case ATTACK_2:
if(Mix_PlayChannel(-1,fireSound,0)<0){
printf("error playing fire sound");
}
actionAttackSdl(fightSdl, ATTACK_2);
break;
case ATTACK_3:
actionAttackSdl(fightSdl, ATTACK_3);
break;
case NOTHING:
actual = ENNEMY;
break;
case -1:
setIsIdleCharacSdl(fightSdl->characSdl,1);
}
}
}
if (nt-t>300){
if(actual == ENNEMY){
hitNRunSdl(fightSdl, monsterId);
if(getMpEnnemyFight(fightSdl->fight) == 3 && getMpEnnemyFight(fightSdl->fight) == 3)
monsterId++;
if(monsterId >= fightSdl->nbMstrSdl){
actual = PLAYER;
setApPlayerFight(fightSdl->fight, 3);
setMpPlayerFight(fightSdl->fight, 3);
monsterId = 0;
}
}
t = nt;
}
// updatePlayerDisplay(fightSdl);
// updateMonsterDisplay(fightSdl);
updatePlayerActionFight(fightSdl);
updateSpellDisplay(fightSdl);
updateDisplay(fightSdl);
drawGame(fightSdl);
// SDL_RenderPresent(fightSdl->renderer);
}
if(getLifePointsCharacter(getCharacterFight(fightSdl->fight)) >= 0)
return 1;
return 0;
}
EDIT : i've added a printf("%s", Mix_GetError) and there is no error in the menu and rpg but in the fight it was print : Invalid audio device ID

So,
I found a solution to solve my problem. Apparently the return value of SDL_OpenAudio is always success or failure, and not a device ID, which means you can only have one device open at a time with this function. I just closed the audio before re-opning it when launching fight, and it works.

Related

Updating array in a function causes pointer lose

I am trying to divide my code into functions, I have a sample code of "Game Of Life".
However, when I try to initialize 2D grid array in a function, gnuplot gives no valid data points error.
These are global variables declared before main:
static char **currWorld=NULL, **nextWorld=NULL
This is the original logic to init game grid, but this part is in main.
if (game == 0){ // Use Random input
for(i=1;i<nx-1;i++){
for(j=1;j<ny-1;j++) {
currWorld[i][j] = (real_rand() < prob);
population[w_plot] += currWorld[i][j];
}
}
}
else if (game == 1){ // Block, still life
printf("2x2 Block, still life\n");
int nx2 = nx/2;
int ny2 = ny/2;
currWorld[nx2+1][ny2+1] = currWorld[nx2][ny2+1] = currWorld[nx2+1][ny2] = currWorld[nx2][ny2] = 1;
population[w_plot] = 4;
}
else if (game == 2){ // Glider (spaceship)
printf("Glider (spaceship)\n");
// Your code codes here
}
else {
printf("Unknown game %d\n",game);
exit(-1);
}
This is my function:
int init_game(int choice, int probability){
int i,j;
if (choice == 0){ // Use Random input
for(i=1;i<nx-1;i++){
for(j=1;j<ny-1;j++) {
currWorld[i][j] = (real_rand() < probability);
population[w_plot] += currWorld[i][j];
}
}
}
else if (choice == 1){ // Block, still life
printf("2x2 Block, still life\n");
int nx2 = nx/2;
int ny2 = ny/2;
currWorld[nx2+1][ny2+1] = currWorld[nx2][ny2+1] = currWorld[nx2+1][ny2] = currWorld[nx2][ny2] = 1;
population[w_plot] = 4;
}
else if (choice == 2){ // Glider (spaceship)
printf("Glider (spaceship)\n");
// Your code codes here
}
else {
printf("Unknown game %d\n",choice);
exit(-1);
}
}
and my function call in main:
init_game(game, prob);
value of game is 0, prob is 0.2 and I tested memory allocations and other stuff, they work fine.
Only difference is I moved the logic to a function. How can this happen? My arrays are global, I cannot understand how it cannot be initialized.
This is the gnuplot error:
Skipping data file with no valid points
Since gnuplot and other functions are works fine, I did not add them but if you need any info, I can add.
Here is the link of file itself:
file

Must freads be in order?

So I'm writing a code for a program with multiple menus that write different struct datas to a file and then with another menu that displays the data written in those files. Here's the code for the menu:
void displayall()
{
FILE *fp;
int choice=0;
struct depart loc = {0};
struct arrive loc1 = {0};
struct travel trav = {0};
fp=fopen("traveldat.dat","r");
while (1)
{
fread(&loc,sizeof(loc),1,fp);
fread(&loc1,sizeof(loc1),1,fp);
fread(&trav,sizeof(trav),1,fp);
double distance,time;
distance = sqrt(pow((loc1.x2-loc.x1),2)+pow((loc1.y2-loc.y1),2));
time = distance/trav.spd;
if (feof(fp))
{
break;
}
printf("\tYour departure location is : %s\n",loc.dep);
printf("\tWith the x-coordinate : %.2f\n",loc.x1);
printf("\tAnd the y-coordinate : %.2f\n\n",loc.y1);
printf("\tYour destination location is : %s\n",loc1.dest);
printf("\tWith the x-coordinate : %.2f\n",loc1.x2);
printf("\tAnd the y-coordinate : %.2f\n\n",loc1.y2);
printf("\tThe distance between these two locations is : %.2fkm\n\n",distance);
printf("\tYour preferred travel method is : %s\n",trav.mthd);
printf("\tWhich has a top speed of : %.2f km/h\n\n",trav.spd);
printf("\tYour expected travel time is : %.2f hours*\n\n",time);
printf("\t*Estimation,actual travel times may vary depending on certain conditions\n\n");
printf("\tThe system will now display the Main Menu\n\n");
}
fclose(fp);
}
The problem I'm facing is that if I go to the menu that writes loc1 or trav before the menu that writes loc, the display menu doesn't work, returns to the main menu, and then refuses to open whenver I try to access it. Is it because fread(&loc) is placed before the other freads? Or is there something I'm missing? Apologies in advance if this code is an eyesore or if I'm asking wrongly, I've only been learning programming for about a month.
Edit: loc1 and loc code as requested
void arrival_location_menu()
{
FILE *fp;
int choice=0;
struct arrive loc1;
fp=fopen("traveldat.dat","a");
printf("Please select your option (Destination location)\n");
printf("1.HOME\n");
printf("2.Andromeda Galaxy\n");
printf("3.The Library\n");
printf("4.Cprogramming.com\n");
printf("5.Return to main menu\n");
scanf("%d",&choice);
fflush (stdin);
switch (choice)
{
case 1: loc1.x2 = 3750;
loc1.y2 = 3450;
loc1.dest = "HOME";
system("CLS");
break;
case 2: loc1.x2 = 9870;
loc1.y2 = 5660;
loc1.dest = "Andromeda Galaxy";
system("CLS");
break;
case 3: loc1.x2 = 1367;
loc1.y2 = 3123;
loc1.dest = "The Library";
system("CLS");
break;
case 4: loc1.x2 = 2133;
loc1.y2 = 4767;
loc1.dest = "stackoverflow.com";
system("CLS");
break;
case 5: system("CLS");
break;
default: printf("Invalid option! Returning you to main menu...\n");
}
fwrite(&loc1,sizeof(loc1),1,fp);
fclose(fp);
return;
}
//DEPARTURE MENU
void departure_location_menu()
{
FILE *fp;
int choice=0;
struct depart loc;
fp=fopen("traveldat.dat","w");
printf("Please select your option (Departure location)\n");
printf("1.UTAR\n");
printf("2.PLUTO\n");
printf("3.IDK\n");
printf("4.UMM\n");
printf("5.Return to main menu\n");
scanf("%d",&choice);
fflush (stdin);
switch (choice)
{
case 1: loc.x1 = 1738;
loc.y1 = 1997;
loc.dep = "UTAR";
system("CLS");
break;
case 2: loc.x1 = 9850;
loc.y1 = 5675;
loc.dep = "PLUTO";
system("CLS");
break;
case 3: loc.x1 = 1363;
loc.y1 = 3125;
loc.dep = "IDK";
system("CLS");
break;
case 4: loc.x1 = 2130;
loc.y1 = 4785;
loc.dep = "UMM";
system("CLS");
break;
case 5:
system("CLS");
break;
default: printf("Invalied option!\n");
}
fwrite(&loc,sizeof(loc),1,fp);
fclose(fp);
return;
}
You seem to be asking if you can read data from anywhere in the file. Yes you can.
There is a function called fseek() to adjust the file pointer. The file pointer is the location next read from or written too.
There is also a function called ftell() to read the current file pointer. That's important if you're going to change the file pointer and want to restore it later.
I would also suggest you get into the habit of initializing variables ( even if it's to NULL or zero ), and of checking return values from functions. These two simple things can make debugging so much simpler.
I believe user #m-m has already explained the coding logic error.

Arduino Switch to Turn a Relay timer

Briefly: I would like to turn on a relay for 30 seconds, after I toggle a switch on.
I'm trying to do a blinds automation at home.
I have a simple ON-OFF-ON switch, attached to an Arduino connected to Relays.
I want to turn on Relay#1 for a maximum of 30 seconds if I toggle the switch down from center. In other words, relay turns on when I switch, and when timer reaches 30 seconds relay turns off.
similarly I want to turn on Relay#2 for exactly 30 seconds if I toggle the switch up from center
And when I switch back to center, I would like the timer to reset.
I could not figure out how. Could anyone help?
I have been trying to use elapsedMillis library for this, which is a nice library that helps me avoid using Delays:
http://playground.arduino.cc/Code/ElapsedMillis
However even though I could work the relays without the 30 second limitation, I couldn't figure out the code to end working of the relays. Here is my current code:
#include <elapsedMillis.h>
#define RELAY_ON 0
#define RELAY_OFF 1
#define RELAY1_TURNS_ON_BLINDS 5
#define RELAY2_SHUTS_DOWN_BLINDS 6
#define shutswitch A0
#define openswitch A1
bool LocalCommandToOpen;
bool LocalCommandToShut;
void setup() ////////SETUP////////
{
digitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_OFF);
digitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_OFF);
pinMode(RELAY1_TURNS_ON_BLINDS, OUTPUT);
pinMode(RELAY2_SHUTS_DOWN_BLINDS, OUTPUT);
pinMode(shutswitch, INPUT);
pinMode(openswitch, INPUT);
} ////SETUP
void loop() { ///////LOOP
if (digitalRead(shutswitch) == 1)
{
LocalCommandToOpen = 1;
}
else
{
LocalCommandToOpen = 0;
}
if ( digitalRead(openswitch) == 1)
{
LocalCommandToShut = 1;
}
else
{
LocalCommandToShut = 0;
}
unsigned int CloseInterval = 14000;
elapsedMillis timeElapsedSinceCloseButtonPush = 0;
unsigned int OpenInterval = 14000;
elapsedMillis timeElapsedSinceOpenButtonPush = 0;
//MANUAL SWITCH OPERATION
if ( LocalCommandToShut == 1 )
{
digitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_OFF);
digitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_ON);
}
else
{
digitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_OFF);
}
//MANUEL DUGME ILE ACMA
if ( LocalCommandToOpen == 1)
{
digitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_OFF);
digitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_ON);
}
else
{
digitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_OFF);
}
delay(500);
} /////////////////LOOP////////////////////////////////////
One suggestion here is to use a "state machine", so that upon a switch transition, you get 'State 1'; in that state, a timer starts, and puts you in 'State 2'. In 'State 2', you check the time, and if it goes beyond X seconds, you go to 'State 3'. You can monitor the transition of a switch from low to high (or high to low), and use this to reset the state of the system.
A sample bit of code gives you an idea of how to implement this. The variable 'SystemState' is an integer, and SYSTEM_ABORT, SYSTEM_IDLE, etc. are constants.
The beauty of this is that the transition is easy to figure out. For example, if you are in the SYSTEM_WAIT state, the only thing you are looking for is the time to be greater than 5 seconds. Also, you can look at input transitions or values to set states (like SystemStopButton == 0, to set the state to be 'SYSTEM_ABORT').
// SystemStopButton is an input
void SystemStateMachine(void)
///////////////////////////////////////////////////////////////////////////////////////////
{
if (SystemStopButton == 0)
{
SystemState = SYSTEM_ABORT;
}
switch (SystemState)
{
case SYSTEM_IDLE:
{
RunPinState = OFF;
StopPinState = OFF;
if (SystemRunButton == 0)
{
SystemState = SYSTEM_START;
ShowStep();
}
break;
}
case SYSTEM_START:
{
StandardMessage = "START ";
RunPinState = ON;
StopPinState = OFF;
SystemState = SYSTEM_WAIT;
ShowStep();
break;
}
case SYSTEM_WAIT: // wait for 5 seconds
{
StandardMessage = "WAIT ";
if ((CurrentMillis - StateStepTimeMillis) > 5000)
{
SystemState = SYSTEM_RETRACT;
ShowStep();
}
break;
}
case SYSTEM_RETRACT: //
{
StandardMessage = "RETRACT";
/* motor stuff goes here... */
if ((CurrentMillis - StateStepTimeMillis) > 5000)
{
SystemState = SYSTEM_ADVANCE_TAPE_WAIT
ShowStep();
}
break;
}
// etc. etc. etc.
case SYSTEM_ABORT: //
{
StandardMessage = "ABORT";
/* motor stop stuff goes here... */
SystemState=SYSTEM_IDLE;
break;
}
default:
{
break;
}
}
}
void ShowStep(void)
/////////////////////////////////////////////////////////////////////
// show step and set time so we can keep track of time in each step
{
Serial.print("SystemState = ");
Serial.println(String(SystemState));
SetStepTime();
}
void SetStepTime(void)
/////////////////////////////////////////////////////////////////////
{
StateStepTimeMillis = CurrentMillis;
}
You might use a state machine; this makes things a bit easier to follow.
Similar to:
Arduino Switch to Turn a Relay timer
A nice discussion of state machines is here:
Complicated state transitions: best practices

Smooth Camera Movement with OpenGL

I've been working with my own game engine for awhile now and I've been trying to get the input and controls to flow much more like a AAA FPS game, or at least a decent indie one. I've posted several topics in the past on this issue about making a smooth camera, and at the time of posting them, I had been satisfied with the results. Now however, I feel that it is not quite smooth enough, and I've switched the whole engine to SDL so I have control over the loop. (previously I was using GLUT). After changing everything to SDL, the mouse is smooth as butter, but the camera movement (walking) is still stutters and looks bad. I've implemented the last of Dwitter's game loop, the one with interpolation, and here is the relevant code:
int main (int argc, char** argv)
{
arg1 = argc;
arg2 = argv;
engineInit();
//the loop has to stay here
//kill all extra threads so they don't cause problems after we quit
//gameloop
SDL_Event event;
bool running = true;
const int TPS = 20;
const int SKIP_TICKS = 1000 / TPS;
const int MAX_FRAMESKIP = 5;
int loops;
long lastSec = 0;
long nextGameTick = SDL_GetTicks();
while (running)
{
while (SDL_PollEvent(&event)) {
//do crap with events
switch (event.type)
{
int x,y,button;
case SDL_QUIT:
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();
cout << "The window has been closed.\n";
running = false;
break;
case SDL_MOUSEMOTION:
SDL_GetMouseState(&x, &y);
passiveMouse(x,y);
break;
case SDL_MOUSEBUTTONDOWN :
button = SDL_GetMouseState(&x, &y);
mouseFunc(button,1,x,y);
break;
case SDL_KEYDOWN:
keyboardDownFunc(event.key.keysym.sym);
break;
case SDL_KEYUP:
keyboardUpFunc(event.key.keysym.sym);
break;
default:
break;
}
}
loops = 0;
while (SDL_GetTicks()> nextGameTick && loops < MAX_FRAMESKIP) {
nextGameTick+=SKIP_TICKS;
loops++;
TickHandler.tps++;
TickHandler.onTick();
int tickTime = int(SDL_GetTicks()/1000);
if (tickTime > lastSec+1)
{
TickHandler.tps = 0;
lastSec = tickTime;
}
}
TickHandler.interpolation = double(SDL_GetTicks() + SKIP_TICKS - nextGameTick )
/ double( SKIP_TICKS );
TickHandler.onRender();
render();
}
Console.consoleActivated = false;
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
TickHandler.onRender() calls a few interpolated functions and here is the one that controls movement of the camera:
void renderTick(float intp)
{
if (cameraPlayer == true)
{
Physics.pos3 = -camy;
Physics.collisions();
Input.applyGravity();
if (Input.walking == true)
Input.moveCameraFirstPerson(1*intp);
else
{
roll = 0;
Input.change = false;
}
}
}
And here is the move camera first person:
void inputs::moveCameraFirstPerson(float speed)
{
speed = speed*walkspeed;
float radx = ((yaw+addedAngle)*MPI/180);
camx -= (sinf(radx)/10)*speed;
camz += (cosf(radx)/10)*speed;
Physics.pos1 = -camx;
Physics.pos2 = -camz;
if (Physics.collided == true)
{float radx = ((yaw+Input.addedAngle)*3.1415926535/180);
camx += (sinf(radx)/20)*speed;
camz -= (cosf(radx)/20)*speed;
Physics.collided = false;
}
Client.x = camx;
Client.z = camz;
Client.y = camy;
Projectile.x = camx;
Projectile.z = camz;
}
I'd love if I could get this all sorted out, any help or references?

"scicosim: error. Type 0 not yet supported for outtb." how to solve this problem?

I'm having an incomprehensible problem in Scicoslab in the last few days.
I've been writing some communication blocks (to send data to an external application) for scicos in C and then wrap them with it's own code. The problem is that, even if the code is working (I've checked every output possible), scicos gives me this error message: sicosim: error. Type 0 not yet supported by outtb. Error Screenshot
Here is the code for the c function of the Sensor Dispatcher Block:
int bro_sens_send (scicos_block *block)
{
int rc, i;
bro_fist_t packet[BUFFER_SIZE];
for (i = 1; i < block->nin; i++) {
bro_encode_sci_datablock(&packet[i-1], block->inptr[i]);
};
printf ("Data for first block: %i, %i, %.2f\n", packet[0].port, packet[0].operation, packet[0].data);
rc = send(block->inptr[0][0], packet, sizeof(bro_fist_t) * BUFFER_SIZE, 0);
if (rc < 0)
{
perror("send() failed");
return -1;
}
printf("%d bytes of data were sent\n", rc);
return 0;
}
int bro_sens_read (scicos_block *block)
{
int rc, i;
bro_fist_t packet[BUFFER_SIZE];
rc = recv(block->inptr[0][0], packet, sizeof(bro_fist_t) * BUFFER_SIZE, 0);
printf("%d bytes of data were received\n", rc);
if (rc < 0)
{
perror("recv() failed");
return -1;
}
printf("Starting to set outputs :3 [%i]\n", block->nout);
for (i = 0; i < block->nout; i++) {
printf("Next Step defining outputs :D [%i]\n", i);
bro_decode_sci_datablock(&packet[i], &block->outptr[i][0]);
printf("Output value for port %i is: %.2f[%i]\n", i, block->outptr[i][0], block->outsz[(2*block->nout)+i]);
}
return 0;
}
void bro_comm_sens_disp (scicos_block *block, int flag)
{
switch (flag) {
case 1: /* set output */
bro_sens_send(block);
bro_sens_read(block);
break;
case 2: /* get input */
break;
case 4: /* initialisation */
break;
case 5: /* ending */
break;
default:
break;
}
}
And this is the code for the block definition (In scilab code):
function [x,y,typ] = SENS_Disp(job,arg1,arg2)
x=[];y=[];typ=[];
select job
case 'plot' then
exprs=arg1.graphics.exprs;
standard_draw(arg1)
case 'getinputs' then
[x,y,typ]=standard_inputs(arg1)
case 'getoutputs' then
[x,y,typ]=standard_outputs(arg1)
case 'getorigin' then
[x,y]=standard_origin(arg1)
case 'set' then
x=arg1
model=arg1.model;graphics=arg1.graphics;
exprs=graphics.exprs;
case 'define' then
model = scicos_model()
model.sim = list('bro_comm_sens_disp',4)
model.out = [1;1;1;1;1;1;1]
model.out2 = [1;1;1;1;1;1;1]
model.outtyp= [1;1;1;1;1;1;1]
model.in = [1;3;3;3;3;3;3;3]
model.in2 = [1;1;1;1;1;1;1;1]
model.intyp = [3;1;1;1;1;1;1;1]
model.evtin = []
model.rpar = []
model.ipar = []
model.dstate=[1];
model.blocktype='c'
model.dep_ut=[%t %f]
exprs=[]
gr_i=['xstringb(orig(1),orig(2),[''Sensors'';+''Dispatcher''],sz(1),sz(2),''fill'');']
x=standard_define([3 2],model,exprs,gr_i)
end
endfunction
The first inpput port for the block is the socket descriptor for communications while the other seven are connected to setup blocks. The outputs returns the data received from the external application.
I've tried to navigate through Scilab code and I've understood that the error I'm getting tells me that the type of data has been set wrongly, but I've checked and it's not quite the case.
Here is the code of Scicoslab that outputs the error:
/*set vectors of outtb*/
for (j=0; j<nlnk; j++) { /*for each link*/
subheader=(int *)(listentry(il_state_outtb,j+1)); /*get header of outtbl(j+1)*/
outtbsz[j]=subheader[1]; /*store dimensions*/
outtbsz[j+nlnk]=subheader[2];
switch (subheader[0]) { /*store type and address*/
/*matrix of double*/
case 1 :
switch (subheader[3]) {
case 0 :
outtbtyp[j]=SCSREAL_N; /*double real matrix*/
outtbptr[j]=(SCSREAL_COP *)(subheader+4);
break;
case 1 :
outtbtyp[j]=SCSCOMPLEX_N; /*double complex matrix*/
outtbptr[j]=(SCSCOMPLEX_COP *)(subheader+4);
break;
default :
Scierror(888,\
"%s : error. Type %d of double scalar matrix not yet supported "
"for outtb.\n",\
fname,subheader[3]);
FREE(outtbptr);
FREE(outtbtyp);
FREE(outtbsz);
FREE(opar);
FREE(oparsz);
FREE(opartyp);
FREE(oz);
FREE(ozsz);
FREE(oztyp);
FREE(lfunpt);
freeparam;
FREE(outtb_elem);
break;
}
break;
/*matrix of integers*/
case 8 :
switch (subheader[3]) {
case 1 :
outtbtyp[j]=SCSINT8_N; /*int8*/
outtbptr[j]=(SCSINT8_COP *)(subheader+4);
break;
case 2 :
outtbtyp[j]=SCSINT16_N; /*int16*/
outtbptr[j]=(SCSINT16_COP *)(subheader+4);
break;
case 4 :
outtbtyp[j]=SCSINT32_N; /*int32*/
outtbptr[j]=(SCSINT32_COP *)(subheader+4);
break;
case 11 :
outtbtyp[j]=SCSUINT8_N; /*uint8*/
outtbptr[j]=(SCSUINT8_COP *)(subheader+4);
break;
case 12 :
outtbtyp[j]=SCSUINT16_N; /*uint16*/
outtbptr[j]=(SCSUINT16_COP *)(subheader+4);
break;
case 14 :
outtbtyp[j]=SCSUINT32_N; /*uint32*/
outtbptr[j]=(SCSUINT32_COP *)(subheader+4);
break;
default :
Scierror(888,\
"%s : error. Type %d of integer scalar matrix not yet supported "
"for outtb.\n",\
fname,subheader[3]);
FREE(outtbptr);
FREE(outtbtyp);
FREE(outtbsz);
FREE(opar);
FREE(oparsz);
FREE(opartyp);
FREE(oz);
FREE(ozsz);
FREE(oztyp);
FREE(lfunpt);
freeparam;
FREE(outtb_elem);
break;
}
break;
default :
Scierror(888,"%s : error. Type %d not yet supported for outtb.\n",fname,subheader[0]);
FREE(outtbptr);
FREE(outtbtyp);
FREE(outtbsz);
FREE(opar);
FREE(oparsz);
FREE(opartyp);
FREE(oz);
FREE(ozsz);
FREE(oztyp);
FREE(lfunpt);
freeparam;
FREE(outtb_elem);
return 0;
break;
}
Ok. After a lot of time I've solved the problem. There was a function that was setting a value in a wrong memory space. The problem was that there weren't any error messages nor warnings.
The problem was in a function that did this:
block->outptr[0][3] = 0;
In a block that had only 3 output ports. This wrote the wrong data inside the data registry. After I removed it everything works fine.

Resources