landelare / ue5coro

A C++20 coroutine implementation for Unreal Engine 5 that feels almost native.
BSD 3-Clause Clear License
543 stars 48 forks source link

Handle *this argument for world context + MSVC crash avoidance #1

Closed redxdev closed 2 years ago

redxdev commented 2 years ago

I totally understand if you don't want to make the conversion to normal templates (which was necessary to get around an MSVC crash on 17.1.3 - latest VS2022) - I can separate that out and just have the *this bit if you want.

When a coroutine is called as a member function (rather than a static/global) the compiler attempts to pass *this as the first argument. For a UObject that'd end up being UObject& so the existing Init(const UObject*) overload wasn't catching it.

Additionally, I had to do some SFINAE trickery on the "default" Init(TFirstArg&, TArgs&...) or else it would get called instead of the UObject overloads (probably because the object being passed in was a derivative of UObject). Not sure if there's a more elegant way to handle that.

redxdev commented 2 years ago

Reference for the *this bit: https://devblogs.microsoft.com/oldnewthing/20210504-00/?p=105176#:~:text=prefixed%20if%20applicable%20by%20the%20hidden%20*this%20parameter