|
Strange error on setting string in text
#338835
08/21/10 23:14
08/21/10 23:14
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
#include <acknex.h>
#include <default.c>
ENTITY* plane_player;
#define TEXT_HANDLE skill73
#define ALIVE skill90
PANEL* main_menu_pan =
{
pos_x = 520;
pos_y = 500;
layer = 2;
alpha = 100;
}
TEXT* comm_speech_txt =
{
pos_x = 100;
pos_y = 150;
string("");
layer = 10;
alpha = 100;
}
function set_text(TEXT *text, int ncol, STRING* s)
{
str_cpy((text.pstring)[0], s);
}
action player_action()
{
me.ALIVE = 1;
player = me;
wait(1);
while(me.ALIVE)
{
wait(1);
}
}
action enemy_action()
{
me.ALIVE = 1;
TEXT* comm_speech_npc_txt = txt_create(1,10);
me.TEXT_HANDLE = handle(comm_speech_npc_txt);
comm_speech_npc_txt.red = 135;
comm_speech_npc_txt.green = 155;
comm_speech_npc_txt.blue = 253;
comm_speech_npc_txt.alpha = 70;
comm_speech_npc_txt.flags = VISIBLE | TRANSLUCENT | SHADOW;
wait(1);
while (me.ALIVE)
{
wait(1);
}
}
function conversation_01(ENTITY* air1, ENTITY* air2, ENTITY* air3)
{
TEXT* text1 = ptr_for_handle(air1.TEXT_HANDLE);
TEXT* text2 = ptr_for_handle(air2.TEXT_HANDLE);
TEXT* text3 = ptr_for_handle(air3.TEXT_HANDLE);
comm_speech_txt.red = 255; comm_speech_txt.green = 255; comm_speech_txt.blue = 255;
comm_speech_txt.flags = VISIBLE | TRANSLUCENT | SHADOW;
set_text(comm_speech_txt, 35, "blah1");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 0; comm_speech_txt.blue = 0;
set_text(comm_speech_txt, 35, "...");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 255; comm_speech_txt.blue = 255;
set_text(comm_speech_txt, 35, "blah2");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 0; comm_speech_txt.blue = 0;
set_text(comm_speech_txt, 35, "...");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 255; comm_speech_txt.blue = 255;
set_text(comm_speech_txt, 35, "blah3");
wait(-1);
text2.red = 150; text2.green = 150; text2.blue = 150;
set_text(text2, 35, "blah4");
wait(-5);
set_text(comm_speech_txt, 35, "blah5");
wait(-1);
text3.red = 150; text3.green = 150; text3.blue = 150;
set_text(text2, 35, "");
set_text(text3, 35, "blah6");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 0; comm_speech_txt.blue = 0; // Osavolk
set_text(comm_speech_txt, 35, "blah7");
wait(-1);
text1.red = 150; text1.green = 150; text1.blue = 150;
set_text(text3, 35, "");
set_text(text1, 35, "...");
wait(-5);
comm_speech_txt.flags = 0;
set_text(text1, 35, "blah8");
wait(-5);
set_text(text1, 35, "blah9");
wait(-5);
set_text(text1, 35, "");
set_text(text2, 35, "blah10");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 0; comm_speech_txt.blue = 0;
comm_speech_txt.flags = VISIBLE | TRANSLUCENT | SHADOW;
set_text(text2, 35, "");
set_text(comm_speech_txt, 35, "blah11");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 255; comm_speech_txt.blue = 255;
set_text(comm_speech_txt, 35, "blah12");
wait(-5);
set_text(comm_speech_txt, 35, "blah13");
wait(-5);
comm_speech_txt.red = 255; comm_speech_txt.green = 0; comm_speech_txt.blue = 0;
set_text(comm_speech_txt, 35, "blah14");
wait(-3);
set_text(comm_speech_txt, 35, "blah15");
wait(-5);
comm_speech_txt.flags = 0;
}
function level_01()
{
level_load ("");
ENTITY* air1; ENTITY* air2; ENTITY* air3;
air1 = ent_create(CUBE_MDL, vector(camera.x + 200, camera.y + 1400, camera.z + 200), enemy_action);
air2 = ent_create(CUBE_MDL, vector(camera.x + 250, camera.y + 2200, camera.z - 100), enemy_action);
air3 = ent_create(CUBE_MDL, vector(camera.x + 200, camera.y + 600, camera.z - 100), enemy_action);
plane_player = ent_create(CUBE_MDL, vector(0, 0, 9800), player_action);
plane_player.skin = 2;
plane_player.pan = 180;
wait(-4);
conversation_01(air1, air2, air3);
wait_for(conversation_01);
}
function main()
{
video_mode = 9;
video_screen = 1;
wait(1);
level_01();
}
Can anyone tell why this program is not working? It crashes after "blah3" sentance with message: "Error E1513 Crash in set_text" If I remove PANEL* main_menu_pan it does work, but that is obviously not a fix. (This is a reduced segment from a much bigger program, took me some time to narrow down the problem.) I am working in version 7.82, but I tried 7.85 too and I get the same error.
|
|
|
Re: Strange error on setting string in text
[Re: Siegewolf]
#338844
08/22/10 01:46
08/22/10 01:46
|
Joined: Dec 2008
Posts: 271
Saturnus
Member
|
Member
Joined: Dec 2008
Posts: 271
|
ptr_for_handle() seems to be the problem here. Sometimes it returns NULL for a valid TEXT handle. This might be an engine bug. The problem also occurs in this little script:
#include <acknex.h>
PANEL* pnl1 =
{
layer = 2;
}
void main()
{
level_load(NULL);
int i;
for (i = 0; i < 3; i++)
{
TEXT* my_txt = txt_create(1,10);
var my_handle = handle(my_txt);
my_txt = ptr_for_handle(my_handle);
if (!my_txt)
{
printf("NULL pointer (handle: %i | hbyte: %i)",
my_handle, my_handle >> 14);
}
else
{
printf("pointer OK (handle: %i | hbyte: %i)",
my_handle, my_handle >> 14);
}
}
}
The problem is somehow related to global PANELs and TEXTs and their layers. With one PANEL ptr_for_handle() fails only one time in the above script. Adding two more PANELs on layer 2 will make ptr_for_handle() fail three times instead.
|
|
|
Re: Strange error on setting string in text
[Re: Siegewolf]
#338845
08/22/10 01:47
08/22/10 01:47
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Educated guesses... Function "set_text(..)" is asking for a STRING*'s, but in the function "conversation_01", you are sending is a char*'s. So try replacing the whole of set_text(...)" with this one.
function set_text(TEXT *text, int ncol, STRING* s)
{
if(text==0) return; //abort if TEXT is faulty
str_cpy((text.pstring)[0], _str(s));
}
If this FIXES the problem, then I was right. BUT, if the problem just gets hidden, and not all the text is appearing as it should, then you'll know youve got a problem with the TEXT creation process in the start of "conversation_01"... (text1 or text2 or text3 arent being created, or pointed to, correctly) [doesnt take into account saturnus's post]
Last edited by EvilSOB; 08/22/10 01:49.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Strange error on setting string in text
[Re: EvilSOB]
#338846
08/22/10 02:05
08/22/10 02:05
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Saturnus: I suspect you are right about it being a bug. I had a play using your code and get the same results. Use this replacement main to see the error a little more clearly. It looks to me like the "ptr_for_handle" function is buggy...
void main()
{
level_load(NULL);
int i;
for (i = 0; i < 20; i++)
{
TEXT* my_txt = txt_create(1,10);
var my_handle = handle(my_txt);
TEXT* my_txt1 = ptr_for_handle(my_handle);
if (!my_txt1)
{
printf("NULL pointer ( TEXT*: %i | handle: %i | hbyte: %i | ptr_for_handle: %i )",
(long)my_txt, my_handle, my_handle >> 14, (long)my_txt1);
}
else
{
printf("Pointer OK ( TEXT*: %i | handle: %i | hbyte: %i | ptr_for_handle: %i )",
(long)my_txt, my_handle, my_handle >> 14, (long)my_txt1);
}
}
}
I suggest putting a post in the BUGS forum... (with your code example...)
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Strange error on setting string in text
[Re: Siegewolf]
#338913
08/22/10 17:36
08/22/10 17:36
|
Joined: Mar 2009
Posts: 23
Siegewolf
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 23
|
|
|
|
|