I think the setctrl() calls are causing the first row to be blank. and that leads to the crash eventually.
I am trying to see if i can avoid doing setctrl() after adding the row.
But i still need to use getctrl() to access the controls. Will try to implement this and see if that fixes the issues.
Interestingly, I don't get any blank first row. Even with the example you provided. (Tested on Win10/11, Linux/Gnome)