Delete_text() Overlapping In More Than One Process?


TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
Can someone explain why the following code doesn't work?

CODE
Program texttest;
Begin
textA();
textB();

Repeat
frame;
Until(key(_esc))

let_me_alone();
exit();

End

Process textA()
Private
String mytext;
Begin
Loop
delete_text(mytext);
mytext = write (0,10,0,0,"Text A");
frame;
End

End

Process textB()
Private
String mytext;
Begin
Loop
delete_text(mytext);
mytext = write (0,10,10,0,"Text B");
frame;
End

End


This is obviously a stripped down version of something else I'm working on.

If I run this, all I see is "Text B". It's as if the write function will only work on one process, or that somehow the TextID is global and the first process (textA) has it's text deleted by the second. In fact, if I delete the "delete_text" lines, I see both lines of text, but quickly get the 512 write lines error.

I feel like I'm doing something dumb here, but I can't see it. Help!


OK, this variant works:

CODE
Program texttest;
Begin
textA();
textB();

Repeat
delete_text(ALL_TEXT);
frame;
Until(key(_esc))

let_me_alone();
exit();

End

Process textA()
Private
String mytext;
Begin
Loop
mytext = write (0,10,0,0,"Text A");
frame;
End

End

Process textB()
Private
String mytext;
Begin
Loop
mytext = write (0,10,10,0,"Text B");
frame;
End

End


But that's crazy. A process should have some level of control over its own text and not leak out into others...

Thanks in advance...
 
If I remember rightly from my Div days, you can't write more than one piece of text at the same location on screen. - you appear to be placing both texts at position 10,10. Try placing A at 11,11 and see if it appears.
 
iprice said:
If I remember rightly from my Div days, you can't write more than one piece of text at the same location on screen. - you appear to be placing both texts at position 10,10. Try placing A at 11,11 and see if it appears.
Actually the first 0 is the fontID. The strings are supposed to be at 10,0 and 10,10, and they appear there properly if I remove the delete_text. It's not a co-ordinate problem.
 
Last edited by a moderator:
Hello, I'll see if I can help.

First of all when you define the Mytext variable you shouldn't be declaring it as a string as when you do mytext = write (0,10,0,0,"Text A"); what happens is mytext then gets the id for the text as an integer, I'm fairly sure changing this will solve your problem as I've never had any problems with deleting text myself.

Secondly you missunderstand the use of the write command, the first value is not the id of the text but the font number to be used. The format of the write command is this - write(font,x,y,flags,"text").
Edit: Sorry, miss read your last reply, I thought you wrote Text ID when you did in fact write Font Id.
 
ruckage said:
Hello, I'll see if I can help.

First of all when you define the Mytext variable you shouldn't be declaring it as a string as when you do mytext = write (0,10,0,0,"Text A"); what happens is mytext then gets the id for the text as an integer, I'm fairly sure changing this will solve your problem as I've never had any problems with deleting text myself.

Secondly you missunderstand the use of the write command, the first value is not the id of the text but the font number to be used. The format of the write command is this - write(font,x,y,flags,"text").
Edit: Sorry, miss read your last reply, I thought you wrote Text ID when you did in fact write Font Id.



Whoops... I guess I screwed up my example... I had a more complex program exhibiting this behaviour and I guess this example was rushed.

Changing it to int doesn't solve the problem. I still see the same behaviour. Is it possible that delete_text acts globally, while write gives a non-unique id?

There's something blindingly obvious I'm missing here. I'll continue staring...

BTW Ruckage I'm a huge fan of your games (IMO the very highest quality homebrew for the GP2x) and they've inspired me to check out fenix for myself. Keep it up!
 
Last edited by a moderator:
More experiments... If I have two writes in each process, it breaks, but if I have three writes in one process and two in another, it works (though the ID's increment like crazy).

If I use say and the debugger, both write statements are allocating the same textID: 1. So one is deleting the other.

I'm thinking the allocation of textIDs isn't synchronized in the write() function. Two processes are simultaneously calling write() and getting the same ID back. In fact I should be able to test that.
 
OK, cleaner code this time:

CODE

Program texttest;
Begin
text("A",10);
text("B",20);
text("C",30);

Repeat
frame;
Until(key(_esc))

let_me_alone();
exit();

End

Process text(String letter, int y)
Private
int mytext;
Begin
Loop
delete_text(mytext);
mytext = write (0,10,y,0,"Text "+letter);
say(letter+" = "+mytext);
frame;
End

End



The visual output for this code is "Text C", and the debug code says A = 1, B = 1, C = 1 over and over again.

I think it's a bug in write(). It's not checking to see if textIDs have been allocated by other processes.
 
OK, I think this clinches it:

CODE

Program texttest;
Private
int i, j, myprocess[3];

Begin
myprocess[0]=text("A",10);
myprocess[1]=text("B",20);
myprocess[2]=text("C",30);
i=0;
Repeat
i++;
i = i % 3;
for (j=0; j<3; j++)
if (i==j)
signal(myprocess[j],S_WAKEUP);
else
signal(myprocess[j],S_SLEEP);
end;
end;
frame;
Until(key(_esc));

let_me_alone();
exit();

End

Process text(String letter, int y)
Private
int mytext;
Begin
Loop
delete_text(mytext);
mytext = write (0,10,y,0,"Text "+letter);
say(letter+" = "+mytext);
frame;
End

End



Forcing two of the three threads to sleep, the screen alternates between Text A, Text B, and Text C. If delete_text affected only one thread, all three of "Text A", B, C should show up solid. I'm deducing from this that write() assigns textIDs independent of other processes.

I'm even more keen to jump into fenix, but it's these little things I want to get a grasp on before diving in to a larger project.

Yikes, it may be even worse than this... It may not remember from loop to loop:

CODE

oldtext=mytext;
mytext = write (0,10,y,0,"Text "+letter);
delete_text(oldtext);



I was hoping to write the new text and delete the old afterwards, but it can't even assign a unique ID for that. It just deletes everything.

Maybe I should just move all my writing off to a single process for safety's sake.

Thanks for anyone taking the time to read this.
 
Hello again.

I've solved your problem. Its not a bug with the write command, the problem is you are deleting text before it exists. Simply move the delete_text after the frame command and it works perfectly. See below for the modified process.

CODE
Process text(String letter, int y)
Private
int mytext;
Begin
Loop
mytext = write (0,10,y,0,"Text "+letter);
say(letter+" = "+mytext);
frame;
delete_text(mytext);
End

End
 
ruckage said:
Hello again.

I've solved your problem. Its not a bug with the write command, the problem is you are deleting text before it exists. Simply move the delete_text after the frame command and it works perfectly. See below for the modified process.

CODE
Process text(String letter, int y)
Private
int mytext;
Begin
Loop
mytext = write (0,10,y,0,"Text "+letter);
say(letter+" = "+mytext);
frame;
delete_text(mytext);
End

End

OK, after a bit of tinkering I get it now. It's a bit tricky, but my bad code is going something like this:

Process A deletes mytext = 0 (ALL_TEXT)
Process A creates TextID = 1 and writes it. A's mytext is set to 1.
Process B deletes mytext = 0 (ALL_TEXT), destroying the previous step
Process B creates TextID = 1 (being the first available) and writes it. B's mytext is set to 1.
The frame is rendered
Process A deletes mytext = 1 as it was told to (destroying the previous step)
Process A creates TextID = 1 (being the first available) and writes it. mytext is set to 1.
Process B deletes mytext = 1 (as it was told to), destroying the previous step
Process B creates TextID = 1 (being the first available) and writes it.
The frame is rendered
repeat

It's when delete_text(undefined) is run on the second process that everything starts to barf.

Thanks Ruckage.. I've got it now.

I think my first game should be out by the end of next week.. :) Got a nice prototype so far.
 
Last edited by a moderator:
Putting code after the frame; command can get tricky when used rigorously, though this is not a huge piece of code. Another way to fix it is doing a write() before your loop, which is not a nice solution seen from a code duplication view.
 
Back
Top