Just checked. If I use ui.bdf & ui.bdc from mame. The above problems goes away but the following crops up.
This started happening when the compile tools were changed. The same code built with different tools gave this result in one build, and not in the other. Changing the compile language to C++ caused the problem to change again...