Jump to content

App is not responding sometimes after world:Update()


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

It's not crashing. The main thread appears to be stuck in a loop maybe. Do you have a C++ program that produces this error?

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

2 minutes ago, Josh said:

It's not crashing. The main thread appears to be stuck in a loop maybe. Do you have a C++ program that produces this error?

I've noticed this issue too. Compiling the application not as a console application usually solves the issue.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Wait, you have this:

 

ListenEvent(EVENT_WIDGETACTION, loadGameButton, loadGameButtonCallback)

 

And this:

local function loadGameButtonCallback(Event, Extra)
    if (game.world == nil) then
        do return end
    end
 --   world:Pause()
    GameLoop()
  --  world:Resume()
end

 

And then this:

 

function GameLoop()
    if (game.isMainMenuOn) then
      --  game.world:Resume()
    end
    game.isMainMenuOn = false
    game.menuPanel:SetHidden(true)
    game.isMenuOn = false
    window:SetCursor(0)
 
    while window:Closed() == false and game.isMainMenuOn == false do  

 

Bro, you got loops within loops.

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

I don't know exactly what is going on here, but your program has a very confusing structure. I can't for sure see anything that is a problem, but I think your issue will go away if you get rid of the second game loop.

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

7 hours ago, reepblue said:

I've noticed this issue too. Compiling the application not as a console application usually solves the issue.

What was structure of app?

 

8 hours ago, Josh said:

Do you have a C++ program that produces this error?

I can try to replicate exactly same app in C++.

 

8 hours ago, Josh said:

The fact that you are creating a new GUI inside an event callback really does not make me feel good.

Why tho? Maybe this is a reason why i have no problem with similar structure in main project, i'm using lambdas instead of events for by buttons there.

 

8 hours ago, Josh said:

Bro, you got loops within loops.

I have two loops for two worlds. Loop inside of loop is just side effect of it :D

What should be approach for few worlds?

I will also to try do it with same loop for this case but i fail to see a problem beside issue that could be related to something else like ui created in event callback.

Link to comment
Share on other sites

In theory it should not matter, but you are calling a C++ function that then goes back into Lua, and there might be something weird I don't know about going on there, when you have layers of interfaces between the two. It makes me nervous.

I tried pausing the program during execution, but it said the program was running external code, which makes me think it is stuck in the Lua library somehow. I also tried to pause from VSCode, but it could not pause. This supports the same hypothesis.

The next thing I can do is build Lua into the engine as C++ instead of a compiled library, or maybe a debug build of the Lua lib, but I don't know if being able to pause inside the Lua VM will tell me anything useful.

I don't think you will be able to recreate this problem in C++.

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

Reproduced it even with one loop in one main.cpp file. Not creating game gui in callback this time. Have no idea what causing an issue now beside switching between worlds which is somehow working in my Quake Tactics project. btw you mentioned that no issue happens with other map - could be a problem related to player controller or something like that?

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;


shared_ptr<World> gameWorld;
shared_ptr<Interface> gameUi;

shared_ptr<Camera> uiCamera;
shared_ptr<Map> gameScene;

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;

shared_ptr<Widget> menuPanel;
bool isMenuOn = false;
bool isMainMenuOn = true;

bool resumeGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    menuPanel->SetHidden(true);
    isMenuOn = false;
    return true;

}

bool mainMenuButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    isMainMenuOn = true;
    return true;
}


bool newGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    isMainMenuOn = false;
    return true;
}

bool exitButtonCallback(const Event& ev, shared_ptr<Object> extra)
{
    exit(0);
    return true;
}

void guiInit()
{
    // Load a font
    auto font = LoadFont("Fonts/arial.ttf");

    // Create user interface
    gameUi = CreateInterface(gameWorld, font, framebuffer->GetSize());
    gameUi->SetRenderLayers(2);
    gameUi->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
    gameUi->LoadColorScheme("Resources/configs/Style.json");

    // Create ui camera
    uiCamera = CreateCamera(gameWorld, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);

    int menuWidth = 200;
    int menuHeight = 200;
    int indent = 25;

    menuPanel = CreatePanel(framebuffer->size.x * 0.5 - menuWidth / 2, framebuffer->size.y * 0.5 - menuHeight / 2, menuWidth, menuHeight, gameUi->root);
    menuPanel->SetColor(0.2, 0.2, 0.2, 1);
    menuPanel->SetLayout(1, 1, 1, 1);
    menuPanel->SetHidden(true);

    int buttonWidth = menuWidth - indent * 2;
    int buttonHeight = 50;
    int posIter = 0;
    int buttonY = indent + posIter * (buttonHeight + indent);
    auto resumeButton = CreateButton("Resume", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
    ListenEvent(EVENT_WIDGETACTION, resumeButton, resumeGameButtonCallback);
    posIter = posIter + 1;
    buttonY = indent + posIter * (buttonHeight + indent);
    auto mainMenuButton = CreateButton("Main Menu", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
    ListenEvent(EVENT_WIDGETACTION, mainMenuButton, mainMenuButtonCallback);
}

int main(int argc, const char* argv[])
{
    RegisterComponents();
    //Load FreeImage plugin (optional)
    auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
    //Get the displays
    auto displays = GetDisplays();
    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);
    //Create a world
    auto world = CreateWorld();

    //Load a font
    auto font = LoadFont("Fonts/arial.ttf");

    //Create user interface
    auto ui = CreateInterface(world, font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(0.2f, 0.2f, 0.2f, 1.0f);
    ui->LoadColorScheme("Resources/configs/Style.json");

    //Create ui camera
    auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);

    auto newGameButton = CreateButton("New game", 200, 125, 200, 50, ui->root);
    ListenEvent(EVENT_WIDGETACTION, newGameButton, newGameButtonCallback);

    auto exitButton = CreateButton("Exit", 200, 200, 200, 50, ui->root);
    ListenEvent(EVENT_WIDGETACTION, exitButton, exitButtonCallback);

    gameWorld = CreateWorld();
    gameWorld->RecordStats();
    WString mapName = "Maps/start.ultra";
    gameScene = LoadMap(gameWorld, mapName);
    guiInit();

    shared_ptr<World> currentWorld = world;
    shared_ptr<Interface> currentUI = ui;

    while (window->Closed() == false)
    {
        if (isMainMenuOn) currentWorld = world; else currentWorld = gameWorld;
        if (isMainMenuOn) currentUI = ui; else currentUI = gameUi;

        if (window->KeyDown(KEY_ESCAPE) == true)
        {
            menuPanel->SetHidden(false);
            isMenuOn = true;
            window->SetMousePosition(framebuffer->size.x * 0.5, framebuffer->size.y * 0.5);
        }
        while (PeekEvent())
        {
            const Event ev = WaitEvent();
            switch (ev.id)
            {
            case EVENT_WINDOWCLOSE:
                if (ev.source == window)
                {
                    exit(0);
                    break;
                }
                break;
            default:
                currentUI->ProcessEvent(ev);
                break;
            }
        }
        currentWorld->Update();
        currentWorld->Render(framebuffer);
    }
    return 0;
}

 

  • Confused 1
Link to comment
Share on other sites

It says sometimes it is stopping in wasapi.c, something to do with the Windows audio system, but I am not convinced this is right.

>    Ultra Engine_d.exe!`anonymous namespace'::WasapiPlayback::mixerProc() Line 719    C++
 

I commented out all the sound stuff but it still happens here...investigating...

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

Okay, it looks like there is something going on with the animation system. If I comment that out I can load and reload with no issues, many times...

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

I can see the send / receive is out of sync.

Sending
Wait result
OK
Sending
Wait result
OK
Sending
Wait result
OK
Sending
Sending
Wait result
OK
Wait result

 

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

  • Solution

Okay, this was simply caused by the animation send state sort of getting out of sync when different worlds are used. Once I figured out what it was it was an easy fix.

I think @Dreikblack deserves a big round of applause.

Episode 1 Applause GIF by Friends

  • Like 2

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

I just updated again, to make sure the right thing got uploaded. Please try it and make sure you updated your project, I tried your original Lua example with no problems.

  • 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...