2

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.

local variables on breakpoint is hit for the first time

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.

local variables on breakpoint is hit for the second time

Then continue the program and the breakpoint is hit again on line 9 and no UE_LOG was executed so far.

local variables on breakpoint is hit for the third time

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)
Bublafus
  • 191
  • 6
  • 2
    This is possible if you debugging a release build code – I S Aug 22 '20 at 08:42
  • You'll want to use a debug configuration, if you've built the engine yourself then you could use DebugGameEditor. Which means all game modules are compiled with no optimisations. I think the configuration for a pre built version is just called Debug. – George Aug 22 '20 at 10:22
  • Thanks, It really was due to the wrong configuration! That opens a different question. Is there a reason in using debugger in Develop configuration? Can I rely on some parts or is the behavior completely undefined? – Bublafus Aug 22 '20 at 14:35

0 Answers0