Jump to content

World Update Hook Invalid Syntax


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

I'm using the latest steam version on the dev branch and get the error popup "Invalid function syntax fot hook ID 2".  This is my code.

void NotificationManager_UpdateHook(shared_ptr<Object> object) {
}
...
void NotificationManager::Init() {
	world->AddHook(HOOKID_UPDATE, NotificationManager_UpdateHook, Self());
}

Based on the parameters for AddHook() my function syntax looks correct... and HOOKID_RENDER works.

Link to comment
Share on other sites

Use this overload:
void AddHook(const HookID id, void (*hook)(std::shared_ptr<Object> source, std::shared_ptr<Object> extra), std::shared_ptr<Object> extra = nullptr);

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Hmm it crashes with an out of memory range error.  My class inherits Object so the function is available and compiles.

void NotificationManager_UpdateHook(shared_ptr<Engine::Object> source, shared_ptr<Engine::Object> object) {
}
...
void NotificationManager::Init() {
	AddHook(HOOKID_UPDATE, NotificationManager_UpdateHook, Self());
}

 

Link to comment
Share on other sites

  • Solution

I had to change the way hooks are inserted into the object info.

In the next build, this example will work:

#include "UltraEngine.h"

using namespace UltraEngine;

struct MyObject : public Object
{
    int count{ 0 };
    
    static void Hook(shared_ptr<Object> source, shared_ptr<Object> extra)
    {
        auto world = source->As<World>();
        auto o = extra->As<MyObject>();
        o->count++;
        Print(o->count);
    }
};

int main(int argc, const char* argv[])
{
    //Get the display list
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1920, 1080, displays[0], WINDOW_CLIENTCOORDS | WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();
    
    auto o = std::make_shared<MyObject>();
    world->AddHook(HOOKID_UPDATE, MyObject::Hook, o);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        Sleep(1000);
    }
    return 0;
}

 

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...