Announcement

Collapse
No announcement yet.

UE_Log crashing engine when trying to print a FString

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

    UE_Log crashing engine when trying to print a FString

    Hi all again,
    I'm trying, in vain, to print a FString from a specific struct contained in a TArray, like this:

    Code:
     struct stuff { int32 first; FString second; };
     TArray<stuff *> stuffList;
     
     FString test = stuffList[x]->second; //x is a valid index
     UE_LOG(LogTemp, Warning, TEXT("%s"), *test);
    No matter what I try it crashes.
    Funnily enough, even AnswerHub crashed when I posted the question there, and had to rewrite the post...
    PORTFOLIO

    #2
    Originally posted by Klawd3 View Post
    Hi all again,
    I'm trying, in vain, to print a FString from a specific struct contained in a TArray, like this:

    Code:
     struct stuff { int32 first; FString second; };
     TArray<stuff *> stuffList;
     
     FString test = stuffList[x]->second; //x is a valid index
     UE_LOG(LogTemp, Warning, TEXT("%s"), *test);
    No matter what I try it crashes.
    Funnily enough, even AnswerHub crashed when I posted the question there, and had to rewrite the post...
    Laughed so hard when I read your second sentence!

    ~~~

    Raw Struct Memory Management

    when you create regular structures or even UE4 C++ UStructs you absolutely must initialize your data members!

    raw structs just get a section of memory that could contain anything, until you initialize the vars you have no idea what's there!

    And so you dont have a clean FString in there, you have a tangled mess that UE4 is dereferencing, so you are dereferencing garbage.

    Try this

    Code:
    struct stuff { 
    	int32 first; 
    	FString second; 
    	
    	stuff()
    	{
    		first = 0;
    		second = "";
    	}
    };
    or this:

    Code:
    struct stuff { 
    	int32 first = 0; 
    	FString second = ""; 
    };


    Rama
    100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

    UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

    Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

    Comment


      #3
      Thanks for the tip Rama.
      PORTFOLIO

      Comment

      Working...
      X