Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strange, strange crash #147295
08/11/07 15:21
08/11/07 15:21
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Hello everyone,

I have a piece of code that I need some help with. I'm actually suspecting this is a Lite-C bug, but I'm posting here first to be sure.

The code crashes at a certain point. If I debug the code, it seems the code magically jumps to a totaly unrelated function. No function call, nothing. It just jumps to the middle of some other function.

When I remove the do..while loop in this function, the code works fine.

Try for yourself, please. Just copy this in a new file and run. The debugger will be activated right away. Then it will do 20 str_cpy's in a loop, and suddenly jump to the other function.

The code may be a bit large, but you don't have to read or understand it. Just confirm that it does not follow the normal path of execution.
Code:

#include <acknex.h>

#define NUM_LINES_IN_CONSOLE 20


FONT* arialFont = "Arial#16";

int numLinesUsed = 0;

TEXT* console =
{
layer = 1;
pos_x = 10;
pos_y = 10;
font = arialFont;
strings = 20;//NUM_LINES_IN_CONSOLE; // Syntax error: Number syntax...??
}

/*
- Name: initConsole
- Desc: initializes the console. Right now, it just makes it visible.
- Params: -
*/
void initConsole()
{
console->flags |= VISIBLE;
if(screen_color.red == 0) screen_color.red = 1;
}

/*
- Name: consoleScrollMessage
- Desc: prints a new message in the console. If the console is full, older messages will
be scrolled up.
- Params: STRING* message - the message to be printed
*/
void consoleScrollMessage(STRING* message)
{
// Check if the console is full:
if(numLinesUsed >= NUM_LINES_IN_CONSOLE)
{
// It is full, move older messages up 1 string:
int i = 0;
for(i = 0; i + 1 < NUM_LINES_IN_CONSOLE; i++)
{
// Copy next string to current string:
str_cpy((console.pstring)[i], (console.pstring)[i + 1]);
}
}
else
{
// The console wasn't full so increment numLinesUsed:
numLinesUsed++;
}

// Finally, print the message (prepended with "> "):
str_cpy((console.pstring)[numLinesUsed - 1], "> ");
str_cat((console.pstring)[numLinesUsed - 1], message);
}

void consoleInkey(STRING* str)
{
consoleScrollMessage("");
str_cpy((console.pstring)[numLinesUsed - 1], " ");

// COMMENT THIS DO WHILE LOOP OUT AND IT WILL WORK:
do {
inkey((console.pstring)[numLinesUsed - 1]);
}
while(result != 13);
str_cpy(str, (console.pstring)[numLinesUsed - 1]);
}
#define CONSOLE_INKEY(str) consoleInkey(str); wait_for(consoleInkey)

/*
- Name: consoleClear
- Desc: clears all lines in the console.
- Params: -
*/
void consoleClear()
{
int i;
for(i = 0; i < NUM_LINES_IN_CONSOLE; i++)
{
str_cpy((console.pstring)[i], "");
}
}

void main()
{
// Print numbers 0 - 20 in the console:
initConsole();
wait(1);

var i = 0;
STRING* strtmp = str_create(" ");
for(i = 0; i < 20; i++)
{
consoleScrollMessage(str_for_num(strtmp, i));
}

// Debugging starts here:
i++;//!
consoleScrollMessage(str_for_num(strtmp, i));
}



Re: Strange, strange crash [Re: Excessus] #147296
08/12/07 08:36
08/12/07 08:36
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
This is interesting, I also had a crash with a do while loop and I now believe that this is a bug in the compiler. Do while lets a previous loop crash. This is the proof:

Code:
 
int result = 0;

void test1()
{
int i;
for(i = 0; i < 10; i++)
{
result = 1;
}
}

void test2()
{

do {
result = 13;
} while (result != 13);
}

void main()
{
test1();
}



This simple program crashes all the time but works when I replace do..while by while {..}. I believe the previous for loop is somehow trashed by the do while loop. I will report this as a bug.

Re: Strange, strange crash [Re: Spirit] #147297
08/12/07 10:51
08/12/07 10:51
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Thanks for looking into this. Let's hope it will be resolved soon..


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1