#yes??

1 messages ยท Page 1 of 1 (latest)

woven oracle
fluid edge
#

what's ItemWidget used for, what is it in your game?

woven oracle
#

the widget im using for drag and drop

#

in that video

fluid edge
#

well try adding missing UPROPERTY to that, in case nothing else is keeping that alive

woven oracle
#

okay

#

It still occurs

woven oracle
#

and it happens only on drop and that too when i pickup the item from the world. It doesnt occur when im drag and dropping the widgets already present in the Inventory

fluid edge
#

are you missing UPROPERTY on any other UObject properties, anywhere?

woven oracle
#

Im but those properties are not related....

fluid edge
#

show those headers?

#

might as well learn a thing or two

#

maybe it'll help find hte actual problem tomorrow shrug

woven oracle
#

wait

#

@fluid edge

fluid edge
#

well... yeah i don't think this is causing your issue but that InventoryGrid should either be a TWeakObjectPtr (if you want this to be a weak pointer to the parent, i.e. this slot class can't keep the inventory grid object alive) or a UPROPERTY(Transient) pointer (if you want the slot class to strongly force its parent to stay alive)

#

when that memcpy crash happens you should copy paste the top chunk of the callstack, do you know how to look through that for clues?

woven oracle
#

nope...

#

I will try to reporduce it

woven oracle
#

Call stack

#

@fluid edge

fluid edge
#

slightly weird looking callstack... what you should do is go to your InventorySystem::NativeOnDragDetected line, and then you can inspect variable data in that code at the time of the crash

#

hopefully you can find something that is maybe nullptr in your locals/autos windows

woven oracle
#

I looked there and the variable data shows invalid

fluid edge
#

also are you in debug config or development?

woven oracle
#

debug

fluid edge
#

well i mean you found the smoking gun at least

woven oracle
#

I found that yesterday....i wanted to know the reason...and like the solution....

fluid edge
#

well......... what data is invalid??

woven oracle
#

the name

#

thats printing in the chinese characters

#

sometimes it becomes invalid triggering the memcpy crash and sometimes it justs prints the data

#

and rest all data is valid tho just the name gets invalid

#
void UItemWidget::NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent, UDragDropOperation*& OutOperation)
{
    Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);
    
    DragWidgetOperation = nullptr;

    //Create new ObjectPayload instance Construct.
    UItemObjPayload* BasePayload = NewObject<UItemObjPayload>(this);
    DragWidgetOperation = NewObject<UDragDropOperationWidget>(); //Create Operation. 
    //if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("ItemQuantity: %d"), BaseItemClass->I_Quantity));

    if (BasePayload && DragWidgetOperation)
    {
        BasePayload->ItemWidget_ref = this;
    if (BasePayload->ItemWidget_ref->GetBaseItemClass()->I_Name != "Gold")
    {
        if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Emerald, FString::Printf(TEXT("Item Widget invalid")));
    }

        DragWidgetOperation->Payload = BasePayload;
        DragWidgetOperation->Pivot = EDragPivot::CenterCenter;
        CreateDraggWidget(DragWidgetOperation);
        OutOperation = DragWidgetOperation;
    }
    if (GEngine) GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Red, BasePayload->ItemWidget_ref->GetBaseItemClass()->I_Name);

}

This is what im doing on drag detected

#

@fluid edge

#

and onDrop, im just passing the reference of ItemWidget ref from the payload

woven oracle
fluid edge
#

i'm not familiar with much UI stuff. does this function run when drag starts, or when it stops (on click, or on release)?

you're making two NewObjects here. are these stored in UPROPERTYs? if not, are they used only within this tick or possibly next frame also?

woven oracle
#

When the drag is detected that means before drag starts

#

and BasePayload is a local variable only used in that block of code while DragWidgetOperation is a private variable not UPROPERTY

#

others wont see this thread right?

fluid edge
#

this discord thread? this is a public server, this isn't a DM

#

so it should be safe to create your BasePayload and then use it right away and let the garbage collector grab it

i assume your crash starts on that last line of that function, obviously

#

split that long call up

#

variable LocalItemWidget_Ref = BasePayload ->ItemWidget_ref;
variable LocalBaseItemClass = LocalItemWidget_Ref->GetBaseItemClass();
variable LocalI_Name = LocalBaseItemClass->I_Name;

then when it crashes use your debugger to look at each of those and see if they're all valid or if one is breaking

woven oracle
fluid edge
#

and as for that DragWidgetOperation... that might be dangerous also, but you haven't answered yet if that UObject is being used only within this tick or in the future after this function creates it

#

you need to have exactly ZERO raw pointers to UObjects in your code

#

they can be safe but only when you know what you're doing, just don't. the only time you might "need" them is usually in like editor slate code

#

either make them TWeakObjectPtr so that the engine sets the variable to nullptr when the thing gets deleted, or make them UPROPERTY so they keep the thing alive and also get set to nullptr if the thing ever gets deleted

woven oracle
woven oracle
#

and what is a raw pointer

fluid edge
woven oracle
#

im supposed to this in the drag detect function?

fluid edge
#
UType* PointerVariable; // raw
UPROPERTY()
TObjectPtr<UType> PointerVariable;
TWeakObjectPtr<UType> PointerVariable;
fluid edge
woven oracle
fluid edge
#

yes

#

raw pointers are not safe to store UObjects in

#

they can only be used for passing them around in functions for local use

#

only UPROPERTY keeps it alive beyond the frame it is created in, study how UE's garbage collector works

woven oracle
#
UPROPERTY(BlueprintReadWrite, Category = "Inventory Grid", meta = (DisplayName = "Current Slot", ToolTip = "Store Current Slot of this Item"))
UBaseSlot* CurrentSlot;

so instead of this i should


UPROPERTY()
TObjectPtr<UBaseSlot> CurrentSlot;
fluid edge
#

what you wrote is fine but in UE5 we will want to start using TObjectPtr<...> instead

woven oracle
#

okay

fluid edge
#

for the immediate problem your UPROPERTY(...) UType* is safe

woven oracle
#

ohh

fluid edge
#

if you mean it's used next tick sometimes or at the end of the drag/drop operation

woven oracle
#

okay

woven oracle