geode icon indicating copy to clipboard operation
geode copied to clipboard

Hook original isn't thread safe

Open SMJSGaming opened this issue 7 months ago • 0 comments

Geode Issue

  • [X] I confirm that this bug is NOT related to a mod but directly to Geode Loader itself.

Platform

Windows

SDK commit

No response

Geode Version

v3.2.0

Mods Installed

No response

Expected Behavior

When creating a custom hook, you can call the original from a task.

#include <Geode/utils/web.hpp>
#include <Geode/Geode.hpp>

using namespace geode::prelude;

web::WebTask WebRequest_send(web::WebRequest* request, std::string_view method, std::string_view url) {
    return web::WebTask::run([&](auto progress, auto cancelled) -> web::WebTask::Result {
        // Calls the original
        request->send(method, url);
    });
}

$execute {
    (void) Mod::get()->hook(
        reinterpret_cast<void*>(addresser::getNonVirtual(&web::WebRequest::send)),
        &WebRequest_send,
        "geode::web::WebRequest::send",
        tulip::hook::TulipConvention::Thiscall
    );
}

Actual Behavior

Inside the task the request seems to be a new pointer, causing it to call the hook again and starting a recursion.

Steps to Reproduce

The code example I posted

Additional Information

No response

SMJSGaming avatar Jul 06 '24 21:07 SMJSGaming