- Modificato
[UE4.20.3/3.7-cpp-beta] Crash calling timeline->getEvents
I've almost finished my port to the cpp version of the runtime, but am having trouble with one remaining thing. I have a method that search the events of the current timeline and returns the time that event is fired. It also crashes to desktop when it attempts to get the events from the timeline object. Please let me know if I'm doing something wrong. Thanks!
Crash stack:
UE4Editor_TalonSpine!spine::Vector<spine::Event *>::Vector<spine::Event *>() [public\spine-cpp\include\spine\vector.h:52]
UE4Editor_TalonSpine!USpineTrackEntry::GetFirstFrameTimeForEvent() [\public\spineanimationcontroller.h:318]
Trimmed down version of my method:
float GetFirstFrameTimeForEvent(FString EventName)
{
if (entry && entry->getAnimation())
{
Vector<Timeline*> timelines = entry->getAnimation()->getTimelines();
if (timelines.size() > 0)
{
for (int i = 0; i < timelines.size(); i++)
{
EventTimeline* timeline = (EventTimeline*)timelines[i];
if (timeline != nullptr)
{
Vector<Event*> events = timeline->getEvents(); //causes crash
}
}
}
}
return(-1);
}
Try
Vector<Event*> &events = timeline->getEvents();
The method returns a reference, the assignment you do would cause a copy, which can do nasty things.
Thanks, this got me in the right direction. If anyone is trying to do something similar, the other piece of the puzzle for me was switching to this logic for the cast:
Timeline *timeline = timelines[i];
EventTimeline* eventTimeline = nullptr;
if (timeline->getRTTI().isExactly(EventTimeline::rtti)) {
eventTimeline = static_cast<EventTimeline *>(timeline);
}