Q: Ack! I'm trying to do something to all items each frame, but ZC acts weird or crashes!
A: Great care must be taken whenever you invoke Waitframe() around pointers. As mentioned here, pointers become stale after each frame, and moreoever there's occasionally even greater subtlety. Consider for instance the following snippet:
Code:
int numitems = Screen->NumItems();
while(true)
{
for(int i=0; i<numitems; i++)
{
item it = Screen->LoadItem(i);
it->X++;
}
Waitframe();
}
Can you spot the problem?
Even though I'm refreshing the item pointers each frame, I'm NOT refreshing the number of items on the screen, so if the number of items decreases (say Link picks one up), one of the LoadItem() calls will return a dangling pointer. The fix is simple; just be sure to recompute both the pointers and the number of items each frame:
Code:
while(true)
{
for(int i=0; i<Screen->NumItems(); i++)
{
item it = Screen->LoadItem(i);
it->X++;
}
Waitframe();
}