ultralight-ux / Ultralight

Lightweight, high-performance HTML renderer for game and app developers.
https://ultralig.ht
4.69k stars 196 forks source link

Application crashes when using FireMouseEvent (Plattform: Windows) #437

Open TheNilusss opened 2 years ago

TheNilusss commented 2 years ago

When i use a FireMouseEvent like this:

MouseEvent evt; evt.type = ultralight::MouseEvent::kType_MouseDown; evt.x = curserPos.x; evt.y = curserPos.y; evt.button = ultralight::MouseEvent::kButton_Left; m_view->FireMouseEvent(evt);

The application crashes when i click on Text or empty space. When i click on a button everything works fine. The Nullpointerexception comes from WebCore.dll

The crashes comes only when i use ultralight::MouseEvent::kButton_Left;

This is so essential for the usage of this framework, pls fix this.

Plattform: Windows Usage: Integration in my Game

Here is my Example HTML: "

Hoverable Buttons

Use the :hover selector to change the style of the button when you move the mouse over it.

Tip: Use the transition-duration property to determine the speed of the \"hover\" effect:

<button class=\"button button1\">Green<button class=\"button button2\">Blue<button class=\"button button3\">Red<button class=\"button button4\">Gray<button class=\"button button5\">Black"

adamjs commented 2 years ago

I'll need more information to reproduce-- is this with latest bins (eg, v1.3 at these links) or is this with v1.2?

Also, please repaste your code as a GitHub Gist and copy the link here.

TheNilusss commented 2 years ago

I use this version: ultralight-sdk-1.2.1-win-x64

The commands are executed in the following order:

Variable Names:

RefPtr<Renderer> m_renderer;
RefPtr<View> m_view;

Config

static void Init() {
    Config config;
    config.resource_path = "./resources/";
    config.use_gpu_renderer = false;
    config.device_scale = 1.0;
    Platform::instance().set_config(config);
}

static void InitPlatform() {
    Platform::instance().set_font_loader(GetPlatformFontLoader());
    Platform::instance().set_file_system(GetPlatformFileSystem("."));
    Platform::instance().set_logger(GetDefaultLogger("ultralight.log"));
}

1 Initialisation

    Init();
    InitPlatform();

    m_renderer = Renderer::Create();
    m_view = m_renderer->CreateView(2560, 1440, true,nullptr);
    m_view->LoadHTML("<html><head><style>.button {background-color: #4CAF50; /* Green */border: none;color: white;padding: 16px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;transition-duration: 0.4s;cursor: pointer;}.button1 {background-color: white; color: black; border: 2px solid #4CAF50;}.button1:hover {background-color: #4CAF50;color: white;}.button2 {background-color: white; color: black; border: 2px solid #008CBA;}.button2:hover {background-color: #008CBA;color: white;}.button3 {background-color: white; color: black; border: 2px solid #f44336;}.button3:hover {background-color: #f44336;color: white;}.button4 {background-color: white;color: black;border: 2px solid #e7e7e7;}.button4:hover {background-color: #e7e7e7;}.button5 {background-color: white;color: black;border: 2px solid #555555;}.button5:hover {background-color: #555555;color: white;}.button5:active {box-shadow: box-shadow:7px 6px 28px 1px rgba(0, 0, 0, 0.24);transform: translateY(4px);}</style></head><body><h2>Hoverable Buttons</h2><p>Use the :hover selector to change the style of the button when you move the mouse over it.</p><p><strong>Tip:</strong> Use the transition-duration property to determine the speed of the \"hover\" effect:</p><button class=\"button button1\">Green</button><button class=\"button button2\">Blue</button><button class=\"button button3\">Red</button><button class=\"button button4\">Gray</button><button class=\"button button5\">Black</button></body></html>");
    m_view->Focus();

2 Game Loop: Each Frame

2.1 Handle

    MouseEvent evt;
    evt.type = ultralight::MouseEvent::kType_MouseMoved;
    evt.x = m_pmanagerGUI->getCurser()->getguipos().x;
    evt.y = m_pmanagerGUI->getCurser()->getguipos().y;
    evt.button = ultralight::MouseEvent::kButton_Left;
    m_view->FireMouseEvent(evt);

    m_renderer->Update();

2.2 Render

    m_renderer->Render();

Graphics and animations works fine.

SupinePandora43 commented 2 years ago

Typical symptom of missing resources/icudt67l.dat, check if resources folder contain this file. If it does, but still is considered missing, remember that "." in GetPlatformFileSystem call is relative to current working directory, not MyApplication.exe the best way (not the best one) would be to use GetPlatformFileSystem(Path.GetDirectory(GetThisExecutablePath())) instead, but you'll have to find ways to get executable's path and it's parent directory by yourself (I'm not in the state of searching it by myself)

"the best" way would be to implement custom filesystem that reads embedded to .exe data.