I have a project in Unreal Engine 4 and I am debugging the game code in Visual Studio 2019. There are some cases when a breakpoint is hit but I believe the code is not really executed. Can you please tell me how is this possible?
1 void UTrace::DrawDebug()
2 {
3 for (TPair<Vector2DTuple, int> edge : EdgesMap)
4 {
5 Vector2DTuple vertices = edge.Key;
6 FVector source = FVector(*vertices.Key, 0.f);
7 FVector target = FVector(*vertices.Value, 0.f);
8
9 DrawDebugLine(GetWorld(), source, target, FColor::Black, false, -1.f, -1, 3.f);
10 UE_LOG(LogTemp, Warning, TEXT("%f %f %f"), source.X, source.Y, source.Z);
11 UE_LOG(LogTemp, Warning, TEXT("%f %f %f"), target.X, target.Y, target.Z);
12 UE_LOG(LogTemp, Warning, TEXT("-------"));
13 }
14 }
I have a breakpoint on line 9 and 11. In the game mode runtime, after the EdgesMap is filled with some element, the breakpoint on line 9 is hit. In this moment the variables seem uninitialized.
Then I press F5 to continue the program and the breakpoint is hit again on line 9 (not line 11 as I would assume). And one of the variables in initialized and the other one is not.
Then continue the program and the breakpoint is hit again on line 9 and no UE_LOG was executed so far.
After that, I continue the program and finally the breakpoint on line 11 is hit and there is one log in the console with correctly initialized variables (x=150, y=650).
Questions:
- Is it some sort of weird Visual Studio behavior or is it some bug in my code?
- How can I tell if the line is really executed?
- Is it somehow linked to the initialization of a local variable?
Observations:
- This weird breakpoint occurs only on the line with the first Draw Debug method. If I put a different call few lines above, than this happens on the prior call.
- The collection EdgesMap has only one element (so the loop has only one iteration for one DrawDebug call)
- The DrawDebug method is only called from a onTick method (it is not called from some constructor)