Page 1 of 1

Surprising quit

PostPosted: Wed Sep 15, 2010 10:25 am
by Leif
Why this code (see below) makes program quit (in 50% of cases) ?

Code: Select all
char* buffer;
sprintf(buffer,"%i",(array1[0]-1)*3+array2[0]);
ChangeAnimation("i_ship_const_blueprint", buffer, FORWARD);


If it is not correct, how to make it work ?

Re: Surprising quit

PostPosted: Wed Sep 15, 2010 12:15 pm
by akr
Your buffer pointer is not initialized

Re: Surprising quit

PostPosted: Fri Oct 01, 2010 2:25 am
by DST
I'm not sure why it isn't working, but here's some red flags that pop into my mind when seeing your code:

1. char buffer[32]; //give it a size

do not use *.

While you're at it, don't name things important words like 'name' or 'buffer'. These may be reserved in some library GE uses, that may cause you problems.

If unsure, just add a new letter at the start. Like Lbuffer.

2. Cap your final result:

char animname[2]; //must be 1 larger than final string(last char is string terminator).
int i=array1[0]-1)*3 etc. etc.

now, depending upon what you have in your anim list (let's say you have 0-9 animations){
if(i<9){
ChangeAnimation.... etc. etc.