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.