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"

Deproject() is crashing the editor.

Using Deproject function is crashing my editor when testing it.

Not sure why it is happening.

.h file

 class AMyProjectHUD : public AHUD
 virtual FVector GetFiringLocation();


 FVector AMyProjectHUD::GetFiringLocation()
     FVector Origin;
     FVector WorldDir;
     const FVector2D Center((Canvas->ClipX * 0.5f), (Canvas->ClipY * 0.5f));
     Canvas->Deproject(Center, Origin, WorldDir);

The function is called in a character class

         APlayerController* MyPC = Cast<APlayerController>(Controller);
         AMyProjectHUD* MyHUD;
         FVector EndLocation;
         MyHUD = nullptr;
         if (MyPC)
             MyHUD = Cast<AMyProjectHUD>(MyPC->GetHUD());
         if (MyHUD)
             EndLocation = MyHUD->GetFiringLocation();

The editor just closes. I tried to remove the deproject part and it works.

Product Version: Not Selected
more ▼

asked May 07 '14 at 02:40 PM in C++ Programming

avatar image

428 77 118 148

avatar image Tim C ♦♦ STAFF May 07 '14 at 04:19 PM

Hi envenger. I attempted to duplicate the issue you were experiencing, but was unable to do so with the code snippets that you provided. Could you provide some more information about what is happening? Please look here to get a better idea of what information would be helpful. In particular, can you reproduce this issue in a brand new project made from one of the available templates? If so, please let me know exactly what steps you take when creating the project, what code you add, and how you add it. Make sure to include as much information as possible, since even seemingly minor details can potentially cause drastically different outcomes if left out.


avatar image envenger May 07 '14 at 05:20 PM

The crash takes place the moment deproject is called. I am trying to replicate it in other ways and see.

avatar image envenger May 07 '14 at 06:40 PM

I found the reason of crash

 const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);

Is crashing it.

avatar image JKapostins May 14 '14 at 02:20 AM

Did you verify that your Canvas object isn't null? You should exercise safer coding standards to prevent potential crashes. For example to protect yourself from crashing on a bad canvas object you could do the following checkf(Canvas, "Canvas is invalid! Deproject will not be called."); if (Canvas) { const FVector2D Center((Canvas->ClipX 0.5f), (Canvas->ClipY 0.5f)); Canvas->Deproject(Center, Origin, WorldDir); }

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Never Call Canvas Outside of Draw HUD

Dear Envenger,

 Canvas->Deproject(Center, Origin, WorldDir);

You are using Canvas outisde of Draw HUD! in a character class!

This is guaranteed crash!

You can't use canvas->project or canvas->deproject outside of the DrawHUD loop

 void YourHUD::DrawHUD()
    if(!Canvas) return;
    Canvas->Deproject / Project

You might ask, how can I get do stuff outside of drawhud related to project and deproject

I'd recommend you just route stuff to your HUD class and do it in the DrawHUD loop



more ▼

answered May 07 '14 at 05:26 PM

avatar image

10.6k 446 346 1088

avatar image envenger May 07 '14 at 06:53 PM

I am doing it in my HUD class but not inside the DrawHUD function.

I couldn't use canvas in character as it was protected.

Thanks for the reply I will find something out.

avatar image envenger May 07 '14 at 07:26 PM

Can Drawcall be called manually from the character?

At what time interval does draw call takes place?

avatar image Rama May 12 '14 at 11:56 PM

you have to only access Canvas from your DrawHUD loop :)

What is your current status?


avatar image envenger May 13 '14 at 11:11 AM

It was easy finished it and it works

avatar image Rama May 14 '14 at 08:55 PM


Congratulations! Yay!


(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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