AttachParent problem

I’m adding an object at my videogame which is suposed to move around automatically inside the player view. So I created in first place a sphere and add a Tick method at my character’s class which will update sphere position. I’ve copy-pasted a code from a working project, but when I play the game, my video card driver crashes and restarts, closing the videogame window giving no time even to render first frame in it… I can’t figure out what I’m doing wrong in this case. Here it is the code:

DLLCharacter.h:


/** Updates Sphere X,Y,Z coordinates */
UFUNCTION(BlueprintCallable, Category = "Sphere")
void TickET();


/** A sphere that have to be shown in front of the camera */
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
class UStaticMeshComponent* SphereVisual;

FVector velocity;
FVector position;

DLLCharacter.cpp:


// First line at default constructor
position = FVector(250.f, 0.f, 50.f);
velocity = FVector(0.f, 0.3f, 0.1f);
//
// ... At the end of the default constructor
//
SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
**SphereVisual->AttachParent = FirstPersonCameraComponent;**
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
if (SphereVisualAsset.Succeeded())
{
	SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
	SphereVisual->SetRelativeLocation(position);
	SphereVisual->SetWorldScale3D(FVector(0.3f));
}


void ADLLCharacter::TickET()
{
	if (SphereVisual != NULL)
	{
		/** screen visibility borders */
		if (position[1] > 250.f || position[1] < -250.f) velocity[1] = -velocity[1];
		if (position[2] > 100.f || position[2] < -140.f) velocity[2] = -velocity[2];

		position += velocity;
		SphereVisual->SetRelativeLocation(position);
	}
}

Specifications:

  • Windows 7 Ultimate 64 bit SP1 (updated).
  • Oculus Rift SDK 2.
  • Oculus Runtime 0.5.0.1.
  • Unreal 4.7.6.
  • Intel core i7 4790K.
  • 16 GB RAM.
  • NVidia Geforce GTX 970. (drivers updated to 355.98).

If I comment the line of AttachParent, it works always. When I attach the sphere to the FirstPersonCameraComponent it crashes. I’ve already tried to attach that sphere to the character’s mesh, but same result :-S.

PS: I’m using OpenCV to process image from video inside the game and show webcam stream as dynamic texture. Anyway, it works perfectly fine without sphere attaching in 100% of the cases.

Am I crafting unproperly this object? Maybe some conflict or running out of video memory? Any tip of what I’m doing wrong??
Best regards,

Ok, I’ve tracked a bit more deeply this issue. I found another critical code line where which can be commented to get the game playable.

I’ve followed this tutorial to integrate my camera and a prerecorded video as dynamic textures inside Unreal: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

at this method:


void AWebcamReader::BeginPlay()
{
	Super::BeginPlay();

	if (videoURL != "")
		stream->open(TCHAR_TO_UTF8(*videoURL));
	else
		stream->open(CameraID);

	if (stream->isOpened())
	{
		//Initialize stream
		isStreamOpen = true;
		UpdateFrame();
		VideoSize = FVector2D(frame->cols, frame->rows);
		size = new cv::Size(ResizeDeminsions.X, ResizeDeminsions.Y);
		
		**VideoTexture = UTexture2D::CreateTransient(VideoSize.X, VideoSize.Y);
		VideoTexture->UpdateResource();**
		
		VideoUpdateTextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, VideoSize.X, VideoSize.Y);

		//Initialize data array
		Data.Init(FColor(0, 0, 0, 255), VideoSize.X * VideoSize.Y);
	}
}

I’ve found that commenting those bold lines setting Videotexture and adding this condition at this method:


void AWebcamReader::UpdateTextureRegions(UTexture2D* Texture, int32 MipIndex, uint32 NumRegions, FUpdateTextureRegion2D* Regions, uint32 SrcPitch, uint32 SrcBpp, uint8* SrcData, bool bFreeData)
{
**	if (Texture && Texture->Resource)**
...
}

instead


**if (Texture->Resource)**

The game is playable, but no dynamic textures are rendered (as expected…)

I knew that sometimes, when asking to OpenCV video dimensions, it could rise some errors when video is direct from the camera input, so I’ve added a prefixed size to texture, instead using VideoSize.X and VideoSize.Y and everything is working but rescaled to these dimensions… :frowning:

Does anybody understands the relation between attach an object to a parent and dynamic texture rendering??? Why if I comment the attaching line everything works with no modifications at the dynamic texture code and if I attach that sphere I have to prefix the size?

Another weird this is that if I prefix the size to 1024x768, it works. If I lock the size to 640x480, it crashes :-O. If I set the surface size to 1080x768, it works too :-S
No matters aspect ratio? This issue rises because not enough memory was allocated (engine issue or not dynamic allocation allowed?). In this case, how is it related to add new objects and attach them to a parent :-_(
Thank you so much and any tip is welcomed.