Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

do not know where is the bug

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

do not know where is the bug

Hi ,

i really did not know the bug in the next function

char  fpsview='FPS %d';
byte  StringFPS[255];
dword FPS;
dword LastTime;

procedure FPScalc()
{
	FPS++;
	GetTickCount();
	Eax -= LastTime;
	if(Eax => 1000)
	 {
		LastTime = Eax;
		wsprintf(@StringFPS,@fpsview,FPS);
		FPS=0;
	 }
}

StringFPS variable is always hold a fiexd string as '!@'

any help please.

http://www.freewebs.com/ogremagic/index.htm

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria
char  fpsview='FPS %d';

='FPS %d'; is a pointer

try

char* fpsview='FPS %d';

then pass it directly without @

alternatively

char fpsview[7];
strlcpy(@fpsview, 'FPS %d', 7);
Colin admin
Posts
928
Threads
49
Location
Bulgaria

btw you could probably do a better job without using wsprintf

char fpsview[255];
dword FPS;
dword LastTime;

procedure FPScalc() {
	char buf[32];
	FPS++;
	eax = GetTickCount();
	eax -= LastTime;
	if (eax => 1000) {
		LastTime = Eax;
		
		strlcpy(@fpsview, 'FPS: ', 6);
		IntToStr(FPS, @buf);
		strAppend(@fpsview, @buf, 255);
	
		FPS = 0;
	}
}

something like this.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok it works.

but seems there is a logical bug in that function because it always hold '1' , it should hold

the frame per second of the animation.

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

LastTime = Eax;

this is it probably, since eax already has sub the lasttime etc, it is no longer gettickcount value

Colin admin
Posts
928
Threads
49
Location
Bulgaria

try

char fpsview[255];
dword FPS;
dword LastTime;

procedure FPScalc() {
	char buf[32];
	FPS++;
	ecx = GetTickCount();
	eax -= LastTime;
	if (eax => 1000) {
		LastTime = ecx;
		
		strlcpy(@fpsview, 'FPS: ', 6);
		IntToStr(FPS, @buf);
		strAppend(@fpsview, @buf, 255);
	
		FPS = 0;
	}
}
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok , thanks here is the correct one

char fpsview[255];
dword FPS;
dword LastTime;

procedure FPScalc() {
  char buf[32];
  FPS++;
  edx = GetTickCount();
  eax -= LastTime;
  if (eax => 1000) {
    LastTime = edx;
    
    strlcpy(@fpsview, 'FPS: ', 6);
    IntToStr(FPS, @buf);
    strAppend(@fpsview, @buf, 255);
  
    FPS = 0;
  }
}

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

there is an other bug here.

the string is growing after each second

for example

FPS: 61
FPS: 6161
FPS: 616161
 ........... etc

http://www.freewebs.com/ogremagic/index.htm