Carbon Events help needed

goldenmeg

Registered
My application runs a simulation model and displays results on a window during the simulation run. Consequently, I need Carbon to handle the HIViewSetNeedsDisplay() periodically while the simulation is running.

I tried attaching the model simulation to a menu command. The model simulation is called in the DoCommand loop. The problem is, the application handles HIViewSetNeedsDisplay() AFTER the DoCommand loop is finished. Consequently, only the very last graphic is displayed and nothing before.

To get around this, I tried to create a custom event with the application as a target. I defined an event class ID and kind. The simulation model is called in the application handler for this event. I wanted it so that if the user selected the menu item to run the model, I would then call CreateEvent() to send the simulation event to the application. This seems simple enough - but the call to CreateEvent() in the DoCommand loop results in a segmentation fault (SIGSEGV).

This was so simple to handle in QuickDraw - I periodically called a graphics routine in my simulation code. How can I handle this with Carbon events?

Thanks, Meg
 
If you need something to happen periodically, you should use an event timer. Call your model simulation in the event timer. You control how often the timer fires. I have an article on event timers at my website, which you can reach by clicking the link in my signature.
 
Will this work even though my model has nothing to do with real time? Basically, when my model finished a loop, I want the new results shown. The time in completing a loop is highly variable. Will "timers" work with a do loop that has no time element? such as

for (i = 1; i < endLoop; i++) {
runModel(i);
showResults(i);
}
ShowFinalResults();
 
It depends on how often you're running the simulation and displaying the results. If you run the simulation once and display the results as the simulation runs, event timers won't help you a lot.

If the simulation is going to be running for a long time, placing your calls to runModel() and showResults() in an event timer will work well. What you have to determine is how fast you want the simulation to run. You'll have to figure out when the simulation is finished so you can turn off the timer and show the final results.
 
Unfortunately, I want to display the results as the simulation runs. So I'm guessing the timers will not help. With QuickDraw, I just passed a window to my grpahics routine and drawed to the grafport. But I can't do that with Carbon?

Any other ideas?? Thanks, Meg
 
If you don't want to use timers, you could use QuickDraw. It's been deprecated in Mac OS X 10.4 so you'll get a bunch of warnings if you compile QuickDraw code on 10.4, but the code will compile. I wouldn't recommend QuickDraw for new code, but you apparently have old QuickDraw code that works, so use it.
 
OK. I'm just surprised that Carbon can't handle this as it is a standard loop for scientific researchers - and many researchers use Macs. Oh well, I'll go back to Quickdraw.

Thanks for your help! Meg
 
Back
Top