S
S
Sergey Grigorov2018-07-26 01:43:00
C++ / C#
Sergey Grigorov, 2018-07-26 01:43:00

Why does the game (and editor) crash when showing/hiding the cursor?

Hello.
There is:
MyGamemode, which has Pawn and PlayerController installed by default in something like this:

#include “MyPawn.h”
#include “MyController.h”

DefaultPlayerController = AMyController::StaticClass();
DefaultPawn = AMyPawn::StaticClass();

My Controller has a method in it
public:
    bool bCursorStatus;
    void AMyController::UpdateCursorStatus(bool bNewCursorStatus, EMouseCursor::Type NewCursor);

Where we, depending on the value of bNewCursorStatus, show / hide the cursor.
There is a certain Pawn, where in:
.h file:
#include “MyController.h”
...
AMyController * GameController;
...
public:
    void CursorManagment();

.CPP file:

void AMyPawn::CursorManagment() {
    if(GameController->bCursorStatus) {
        GameController->UpdateCursorStatus(false, EMouseCursor::Hand);
    }
    else {
        GameController->UpdateCursorStatus(true, EMouseCursor::Hand);
    }

I also tried to simply install in this method:
GameController->bMouseShowCursor = false;
CursorManagment () is called by pressing the Left Ctrl key.
But the editor is safely cut out (it crashes) immediately after pressing Ctrl.
There are no errors in the code (now I am writing from the phone, I could distort the names of the arguments / methods), it compiles without errors.
It crashes when you try to change the visibility of the cursor, etc. its attributes in the body of this method in both ways.
I would like to know the cause and solution of this problem (hiding / showing the cursor on a keystroke from C ++).
To handle pressing, I use the BindAction of the PlayerInputComponent with IE_Released, the key is set in Project Settings in Action Mapping.
At the same time, if you do not change the cursor parameters in the body of this method, but, for example, output something via GEngine->AddOnScreenDebugMessage(), then everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-07-26
@Serjio-Grig

If the crash occurs with a single-line code, then the problem is clearly that the GameController is not initialized or points to memory that has already been freed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question