x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

CreateDefaultSubobject crashes editor

The following function causes the editor to crash once the compile button is hit:

 #define NUM_CHUNKS 26
 #define CHUNK_PATH_PFX "/Game/Models/cube-fractured_Cube_cell_"
 void ATargetDestructible::LoadChunkedMesh()
 {
     FString basePath = TEXT(CHUNK_PATH_PFX);
     for (int x = 0; x < NUM_CHUNKS; x++)
     {
         FString chunkNum = FString::Printf(TEXT("%03d"), x);
         FString chunkPath = basePath + chunkNum;
 
         UE_LOG(LogTemp, Log, TEXT("%s"), *chunkPath);
 
         // Start crash inducing code
         UStaticMeshComponent *chunk = NULL;
         chunk = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChunkMesh"));
         chunk->SetupAttachment(RootComponent);
         // End crash inducing code
 
         ConstructorHelpers::FObjectFinder<UStaticMesh> asset(*chunkPath);
         if (asset.Succeeded())
             chunk->SetStaticMesh(asset.Object);
     }
 }
 #undef NUM_CHUNKS
 #undef CHUNK_PATH_PFX

Is there a workaround, or am I off the path on how to dynamically load a long list of similar named assets?

Update 1

I've managed to slim it down to the following:

 void SomeClass::SomeFunction(int *p)
 {
     // Ok
     for (int x = 0; x < *p; x++)
     {
         UStaticMeshComponent *chunk = NULL;
         chunk = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChunkMesh"));
         chunk->SetupAttachment(RootComponent);
     }
 
     // Ok
     for (int x = 0; x < 1; x++)
     {
         UStaticMeshComponent *chunk = NULL;
         chunk = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChunkMesh"));
         chunk->SetupAttachment(RootComponent);
     }
 
     // Crashes
     for (int x = 0; x < 2; x++)
     {
         UStaticMeshComponent *chunk = NULL;
         chunk = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChunkMesh"));
         chunk->SetupAttachment(RootComponent);
     }
 }

The only thing I can think of is that it must be pretty aggressive on loop unrolling and it is breaking somewhere with that? This is only compiling in debug mode, so I wouldn't think it would get that aggressive?

Update 2

When setting the pointer as volatile, it still produces the crash when more than 1 loop iteration is needed. Side note, why is the compiler ignoring volatile?

 void SomeClass::SomeFunction()
 {
     int x = 2;
     AnotherFunction(&x);
 }
 
 void SomeClass::AnotherFunction(volatile int *p)
 {
     for (int x = 0; x < *p; x++)
     {
         UStaticMeshComponent *chunk = NULL;
         chunk = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ChunkMesh"));
         chunk->SetupAttachment(RootComponent);
     }
 }

Product Version: UE 4.14
Tags:
more ▼

asked Jan 27 '17 at 06:30 PM in Bug Reports

avatar image

nathansizemore
82 4 7 12

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Two problems I can think of:

  1. You can't have more than one component with the same name in an actor. You'll have to do something like appending x to the end of "ChunkMesh" so you have unique names.

  2. CreateDefaultSubobject can't be run outside of a constructor. If this isn't running in your constructor you should use NewObject instead, and make sure you also call RegisterComponent when you finish setting up its attachment and and extra processing you need to do.

more ▼

answered Jan 27 '17 at 07:34 PM

avatar image

kgamble
904 39 56 199

avatar image nathansizemore Jan 27 '17 at 07:42 PM
  1. The unique naming makes sense.

  2. It is inside a constructor

Still curious as to why the compiler ignores volatile.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question