Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: OnEndPlay delegate not called on end of PIE #230

Open
vrachels opened this issue Nov 8, 2018 · 4 comments
Open

bug: OnEndPlay delegate not called on end of PIE #230

vrachels opened this issue Nov 8, 2018 · 4 comments

Comments

@vrachels
Copy link

@vrachels vrachels commented Nov 8, 2018

STR:
add JavascriptComponent to a game mode used for the level
in javascript: Root.OnEndPlay.Add(()=> { ... (log message or somesuch) });
play in editor

note that the function is not called.
Putting a breakpoint in and stepping into UJavascriptComponent::Deactivate shows that the delegate has been destroyed.
It is possible/likely for the components JavascriptContext to be destroyed before the component is destroyed.
Ie: note that a breakpoint in UJavascriptIsolate::BeginDestroy() is hit before the UJavascriptComponent::Deactivate is hit.

A fix for PIE is to call the OnEndPlay via the EndPlayMap delegate (which is called before any objects are destructed in PIE)

ie:

JavascriptContext = Context;
FGameDelegates::Get().GetEndPlayMapDelegate().AddLambda([this]()
{
	FGameDelegates::Get().GetEndPlayMapDelegate().RemoveAll(this);
	this->OnEndPlay.ExecuteIfBound();
});

I am not certain if this reproduces in standalone..

@crocuis

This comment has been minimized.

Copy link
Contributor

@crocuis crocuis commented Nov 27, 2018

Try to attach JavascriptComponent to Your gameState.

@vrachels

This comment has been minimized.

Copy link
Author

@vrachels vrachels commented Nov 27, 2018

Same result.
Cleanup from PIE is done in one pass of the garbage collector, and results in many objects being added to the destroy queue at the same frame. The calls to destroy may not be deterministic (though it seems likely a direct result of the dependency graph), but I am consistently seeing the Isolate being destroyed before the JavascriptComponent, whether it is on the gamestate or the gamemode.

@crocuis

This comment has been minimized.

Copy link
Contributor

@crocuis crocuis commented Dec 20, 2018

It's hard to understand exactly what you want, but in this situation it's better to use Destroyed as a callback than Actor's OnEndPlay.

@vrachels

This comment has been minimized.

Copy link
Author

@vrachels vrachels commented Dec 20, 2018

I've added a hook to when the game ends. (my particular use case is for a flush of delayed writes)

I'm not so much interested in an individual actor's onEndPlay - in the unreal JS, I'm using the Root.OnEndPlay delegate to add a 'before the game ends, do XYZ'.

Effectively equivalant to process.on('exit', callback) I've added to our polyfill/timers.js process object to use it this way, creating an array of individual callbacks to be executed by the OnEndPlay callback. As described in this bug, the callbacks were never being executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.