Can you you reproduce the behavior with the first implementation with global variables? It indicates a potential problem with your program, i.e. overwriting memory accidental from other parts of the program. You should follow up on that. With your changed design now other memory areas may get overwritten uncontrolled. if possible set a break or watch point on any change to the variable which is changed unexpectedly, and let the program run.
... View more