Announcement

Collapse
No announcement yet.

Attempting to log debug messages causing crash

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Originally posted by Alters View Post
    In regards to the TempArray being declared as a pointer I thought that it was the more 'optimized' way to do it - point to the reference of all the variables and see what they were rather than directly copying them all over. Am I doing this part incorrectly?
    I believe its because dynamic arrays(in case TArray) are already pointers in the background.So you dont initialize them as a pointer again.

    Leave a comment:


  • replied
    It seems the only difference there is that the AActor* hitActor is declared as a pointer while my FVector2D isn't. A quick fix changing it to FVector2D* CurVector and removing the dereference allows it to work fine. Are these not technically the same thing though as declaring it not as a pointer and dereferencing TempArray to it?

    In regards to the TempArray being declared as a pointer I thought that it was the more 'optimized' way to do it - point to the reference of all the variables and see what they were rather than directly copying them all over. Am I doing this part incorrectly?

    Leave a comment:


  • replied
    Actually you dont need to deference-reference those like that.Have a look at this.
    Code:
    TArray<FHitResult> fHitRes;
    ......
    bool result = w->SweepMulti(fHitRes,rayStart,rayStart+radius,FQuat::Identity, ECollisionChannel::ECC_PhysicsBody, shape, fqp);
    if(result)
    {
         for( int i = 0; i < fHitRes.Num(); ++i )
         {
    			AActor* hitActor = fHitRes[i].GetActor();
    			if( hitActor )
                            {
                             ..............
                            }
         }
    Why are you declaring your array as a pointer? AFAIK arrays in C++ are already pointers.

    Code:
    return &PressedLocations;
    What you do here,you return the PressedLocations's memory address but you dont use the memory address in order to use the information later.
    Last edited by arkenthera; 04-10-2014, 04:00 PM.

    Leave a comment:


  • replied
    Originally posted by arkenthera View Post
    probably
    Code:
    CurVect = *TempArray[b].GetData();
    this line of code.Why casting it like that?
    Without it I get: (error C2679: binary '=' : no operator found which takes a right-hand operand of type 'FVector2D *' (or there is no acceptable conversion))

    I could be wrong but is that not the proper way to dereference a pointer?

    For reference this is what I have and what I'm trying to do:

    Code:
    TArray<FVector2D> PressedLocations; - under protected in one of my classes. A dynamic array of 2d Vectors.
    
    TArray<FVector2D>* ReturnPressedLocations(); - Function I am using to return the values in the array. I believe this should be returning a reference to the dynamic array.
    
    TArray<FVector2D>* AMyProject2PlayerController::ReturnPressedLocations()
    {
    	return &PressedLocations;
    }
    Code:
    --Separate Class--
    TArray<FVector2D>* TempArray;
    AMyProject2PlayerController* AMPC = Cast<AMyProject2PlayerController>(GetOwningPlayerController());
    
    if (AMPC != NULL)
    {
    	TempArray = AMPC->ReturnPressedLocations();
    	if (TempArray != NULL)
    	{
    		FVector2D CurVect;
    		for (int32 b = 0; b < TempArray->Num(); b++)
    		{
    			if (TempArray[b].GetData() != NULL)
    			{
    				CurVect = *TempArray[b].GetData();
    				//Crash spot if there are log messages here trying to access info about CurVect
    			}
    		}
    
    		UE_LOG(LogLevel, Warning, TEXT("Temparray isn't none. Length is: %i"), TempArray->Num());
    	}
    }
    In hindsight it looks like I've done a few things wrong and that I should continue to read up about pointers, references, and the such. If anyone could still point me in the right direction of what I specifically did wrong though, I'd appreciate it.

    Leave a comment:


  • replied
    probably
    Code:
    CurVect = *TempArray[b].GetData();
    this line of code.Why casting it like that?

    Leave a comment:


  • started a topic Attempting to log debug messages causing crash

    Attempting to log debug messages causing crash

    I'm probably missing something simple here but when attempting to log messages using UE_LOG I'm getting a crash the second time it attempts to log. I can see that it logged one message and then when the next loop runs it immediately crashes. Using Visual Studio and debugging I can see that CurVect is getting the proper values but it is saying that (after the second frame runs as mentions above) it is crashing on setting a value to CurVect.

    If there is no log message it doesn't crash.

    Code:
    TArray<FVector2D>* TempArray;
    FVector2D CurVect;
    
    TempArray = AMPC->ReturnPressedLocations();
    if (TempArray != NULL)
    {
    for (int32 b = 0; b < TempArray->Num(); b++) { if (TempArray[b].GetData() != NULL) { CurVect = *TempArray[b].GetData(); //UE_LOG(LogLevel, Warning, TEXT("Log message that doesn't crash")); UE_LOG(LogClass, Log, TEXT("Log message that crashes: %f"), CurVect.X); //UE_LOG(LogLevel, Warning, TEXT("Log message that also crashes: %s"),*CurVect.ToString()) } }
    }
    Any help is appreciated. I'm hoping it's just something simple I'm missing.
    Last edited by Alters; 04-10-2014, 02:01 PM.
Working...
X