from normal C++ class to UCLASS

hiho

now I use TArray instead of std::list …
but now UE4 Crashes xD

my Code:

SkiGr.h




UCLASS(Blueprintable, BlueprintType)
class DYNAMO_API USkiGr : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    ASkill * element;
    TArray<USkiGr*> childs;
    TArray<USkiGr*> parents;
    USkiGr();
    USkiGr(ASkill* );
    ~USkiGr();
    USkiGr* makeNewChild(USkiGr* inTree);
    UFUNCTION(BlueprintCallable, category = "Own|Graph")
    USkiGr* makeNewChild(ASkill* inValue);
    bool pushChildtoParent(USkiGr* );
    UFUNCTION()
    bool deleteChild(USkiGr* );
    UFUNCTION(BlueprintCallable, category = "Own|Graph")
    bool makeParent(USkiGr* newParent);
    UFUNCTION(BlueprintCallable, category = "Own|Graph")
    ASkill* getElement();
    bool leaf;

};



and SkiGr.cpp



// Fill out your copyright notice in the Description page of Project Settings.

#include "SkiGr.h"


USkiGr::USkiGr()
{
    leaf = true;
    element = nullptr;
}


USkiGr::USkiGr(ASkill* element) : element(element)
{
    leaf = true;
}


USkiGr::~USkiGr()
{
    if (!leaf)
    {
        for (int it = childs.Num()-1; it>=0 ;it--)
        {
            // wenn das kind nicht mehrere Väter hat, denen ich es nicht weg nehmen will
            if ((*childs[it]).parents.Num()<2)
            {
                childs[it]->ConditionalBeginDestroy();
                childs[it] = nullptr;
                childs.Remove(childs[it]);
            }
            else {
                (*childs[it]).parents.Remove(this);
                it++;
            }
        }
    }
    if (!(*this).parents.Emplace())
    {
        for (int it = 0; it < parents.Num(); it++)
        {
            //alle Väter vergessen dieses Kind, damit es ohne folgen beseitigt werden kann
            (*parents[it]).deleteChild(this);
        }
    }
}


ASkill* USkiGr::getElement()
{
    return (*this).element;
}


bool USkiGr::deleteChild(USkiGr* tokill)
{

    {
        for (int it = 0; it < childs.Num(); it++)
        {
            if (childs[it] == tokill) {
                childs.Remove(childs[it]);
                return true;
            }
        }
    }
    // Error code hier einfügen
    return false;
}

//eingane der zu setzende Vater. Wenn setzen des Vaters gelingt, wird er in die Liste der Väter aufgenommen


bool USkiGr::makeParent(USkiGr* newParent) {
    if ((*newParent).pushChildtoParent(this)) {
        parents.Add(newParent);
        return true;
    }
    else {
        //Error code hier einfügen
        return false;
    }
}


bool USkiGr::pushChildtoParent(USkiGr* inTree) {
    childs.Add(inTree);
    leaf = false;
    return true;
}


USkiGr* USkiGr::makeNewChild(ASkill* inValue)
{
    USkiGr* contain = NewObject<USkiGr>(inValue);
    childs.Add(contain);
    (*contain).parents.Add(this);
    leaf = false;
    return contain;
}


USkiGr* USkiGr::makeNewChild(USkiGr* inTree)
{
    childs.Add(inTree);
    (*inTree).parents.Add(this);
    leaf = false;
    return inTree;
}


I think, it shoud be a Memory-Problem that I miss something with the GC, ore It crash curse of the TArray :confused:
it would be nice, if you can help me at this point …

The only help, UE4 tell me is this
Unbenannt2.PNG
and if I start it at VS, this is all I get

Unbenannt2.PNG
(Triggered exception: read access violation “this” was a “nptr”)
(it is not possible to make it at VS English curse I have to Download the Language and I have at the moment only 0,01Mb/s, if I have WLAN at all xD)

it would be nice, if you can help me :slight_smile:

Best wishes
EvD