I am looking into the answers to your questions; unfortunately I do not have easy access to a Panda installation this week so it may take me a little bit to get a chance to duplicate your problem. But here is what I can say off the top of my head:
That crash is disturbing. I don’t see that you are doing anything wrong (although you probably don’t really want to be applying a scale to aspect2d; you should probably create an interim node, or scale each button, instead). What is the nature of the crash? Are you sure that your Panda is correctly built?
Where your function event_button_click looks something like this:
void
event_button_click(CPT_Event event, void *data) {
int i = (int)data;
cerr << "got button click: " << i << "\n";
}
In my example, I am casting an integer to a void pointer, which is not strictly proper but usually works. Strictly, you should use the void pointer to pass a pointer to any data structure you like (“this” is commonly used).
Hmm, are you explicitly calling delete on the buttons that you allocated with new? If you are, you should not, since that will certainly cause a crash (the PT(PGButton) object automatically calls delete for you).
Also, it’s possible it’s related to the sound library. Try disabling sound completely by putting:
audio-library-name null
in your Config.prc.
In my own tests, I am able to create 50 buttons without crashes at exit or any other time, pasting in largely the code that you posted above.
I did, however, discover an error in PGButton::setup() that is causing the label to be obscured by its bevel. I apologize for the error; it’s an example of code rot in rarely-exercised code (most people use the Python DirectButton interface, which doesn’t use the setup() call). I have fixed the bug and the fix will be released in a future version of Panda.