#yes??
1 messages ยท Page 1 of 1 (latest)
what's ItemWidget used for, what is it in your game?
well try adding missing UPROPERTY to that, in case nothing else is keeping that alive
its hard to understand what im doing wrong to cause the memory corruption
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
are you missing UPROPERTY on any other UObject properties, anywhere?
Im but those properties are not related....
show those headers?
might as well learn a thing or two
maybe it'll help find hte actual problem tomorrow 
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?
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
I looked there and the variable data shows invalid
also are you in debug config or development?
debug
well i mean you found the smoking gun at least
I found that yesterday....i wanted to know the reason...and like the solution....
well......... what data is invalid??
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
im actually getting the Widget reference from the payload and then I have a slot reference in Item widget which im changing to like yk swapping places
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?
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?
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
usually it happens on drop, but the I_Name variable's value gets corrupted from here
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
DragWidgetOperation is getting used outside the function
i didnt understood this
and what is a raw pointer
Thing->Var->Function()->Var gives you no individual bits of data to debug
im supposed to this in the drag detect function?
UType* PointerVariable; // raw
UPROPERTY()
TObjectPtr<UType> PointerVariable;
TWeakObjectPtr<UType> PointerVariable;
yes, to make your code user-friendly (debuggable)
So the ObjectPtr is normal pointer and WeakObjectPtr is Weak pointer?
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
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;
what you wrote is fine but in UE5 we will want to start using TObjectPtr<...> instead
okay
for the immediate problem your UPROPERTY(...) UType* is safe
ohh
but this, without UPROPERTY, is a guaranteed crash
if you mean it's used next tick sometimes or at the end of the drag/drop operation
okay
I thought UPROPERTY is only used for exposing variables in bp