First of all, your code should exhibit the problem you are having and should be a self-contained, and a reproducing example. More guidelines can be found in “The Short, Self Contained, Correct, Example” (= SSCCE) page and in Stack Overflow’s “Minimal, Reproducible, Example” page (whose text is under CC-BY-SA).
If the code is too large, please consider reducing it to a more minimal example that still exhibits the problem (see the bisection method ). Namely, you can try gradually removing parts of the code while each time ascertaining that the problem can still be reproduced until you have reached the shortest possible code. Often, doing that will be enough to find the culprit reason for the failure and to fix it.