Surprising quit

Game Editor comments and discussion.

Surprising quit

Postby Leif » Wed Sep 15, 2010 10:25 am

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 ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Surprising quit

Postby akr » Wed Sep 15, 2010 12:15 pm

Your buffer pointer is not initialized
Co-Developer of GE engine

If u are interrested in new features of apple or android ge engines check the engine support website game-editor.net regulary.
akr
 
Posts: 453
Joined: Thu Feb 25, 2010 7:56 pm
Location: Germany, Ulm
Score: 40 Give a positive score

Re: Surprising quit

Postby DST » Fri Oct 01, 2010 2:25 am

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron