I had the same problem with adding panels by defining them with PANEL* so I
created new function with "pan_create(char* content, var layer)" in it and it worked.

As for invalid arguments, my guess is that some pointer is NULL when it should not be.
You could try to pinpoint exact pointer and adding a line before it:
while(that_pointer==NULL) wait(1);

I'm sorry I cant help you much because I don't have that problem with "attach_weapon" and everything else, except panels, is working normal.

Good luck!