Program exit (and other strange behaviors)

More
2 weeks 5 days ago - 2 weeks 5 days ago #60 by rosogon
I am attaching a file that runs a while (!esc pressed), but the execution is halted when the state changes. I left the code to the bones so it does not make sense, but it still triggers the issue. The program initializes status=1, then set status=0 and then halts. Note that I am automatically setting status to 0 for your convenience, but it also happens if the change is due to a button press in the pad, f.e..

I cannot ensure it is not a bug in my code, but I removed all memory handling (sprites) and it still fails.

This is my investigation:

The handle() function has the following structure: 
Code:
void handle(id) {   alive = ...   if (!alive) {     return;   }   do things }


When !alive, the execution is halted (maybe at this point, maybe later), like if it were returning to a wrong address.

From this code:
* If you uncomment lines 31 and 41 so the structure is if (!alive) { return } else { do things }, then it does not fail.
* If you comment out lines 35 to 40, it takes longer to fail, but fails.
* If you comment out line 33 to 40, it does not fail.

Note that check function contains the same kind of if but it works OK.
   
There is a debug function. I have a longer file where setting debug to False did not triggered the issue.

Other behaviors that I have found. Depending on the code, it fails with a "Runtime error" in red (I am not sure of the message). Twice it has happened that it created a file in the card with just a symbol as name (I think it is the ALT-A symbol).
 
Last edit: 2 weeks 5 days ago by rosogon.

Please Log in or Create an account to join the conversation.

More
2 weeks 4 days ago #61 by Franck
Thanks for the report. I will investigate. Memory is filled at start with zeroes, and that's the HALT opcode. So most likely it jumps randomly to memory and halts. Sometimes it might end up elsewhere on an unknown opcode and that triggers the runtime error. So your assumption is probably right that it gets a wrong return address for some reason.

Please Log in or Create an account to join the conversation.

More
2 weeks 4 days ago #62 by rosogon
I also found that if a function returns a value, the value MUST be assigned to something. See the following:
Code:
int f(int i) {   print(i);   return i; } while (_keyDwn != 12) {   f(0); }

Expected: infinite loop of printed 0s
Actual: execution ends after 3.25 rows of 0s. 

Issue is gone if doing int i = f(0);

I am running 0.7.4.

Please Log in or Create an account to join the conversation.

More
2 weeks 5 hours ago #63 by Franck
Both bugs have been fixed for 0.7.5
The following user(s) said Thank You: rosogon

Please Log in or Create an account to join the conversation.

Time to create page: 0.172 seconds
Powered by Kunena Forum