Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the create and delete of the app intentional in EntryPoint.h? #73

Open
glenpierce opened this issue Mar 1, 2024 · 3 comments
Open

Comments

@glenpierce
Copy link

glenpierce commented Mar 1, 2024

In EntryPoint.h,

int Main(int argc, char** argv)
{
while (g_ApplicationRunning)
{
Walnut::Application* app = Walnut::CreateApplication(argc, argv);
app->Run();
delete app;
}
return 0;
}

This code appears to have a logical error, as it creates and deletes a new Walnut::Application object in each iteration of the while loop. This means that the application is constantly being restarted and terminated, which is probably not the intended behavior. A more reasonable approach would be to create the application object once before the loop, and delete it once after the loop, like this:

namespace Walnut {

    int Main(int argc, char** argv)
    {
        Walnut::Application* app = Walnut::CreateApplication(argc, argv);

        while (g_ApplicationRunning)
        {
            app->Run();
        }

            delete app;

            return 0;
    }

}

Please correct me if I'm mistaken here, Or maybe there's a good reason for it, I'm very new to this project.

@glenpierce
Copy link
Author

glenpierce commented Mar 1, 2024

Update: I got courageous and tried it. My solution is... not good. It causes the app to crash when I try to exit/close the window.

If anyone has the time to explain why this loop is doing this, I would be quite thankful. This is a bit confusing to me.

@learn-more
Copy link

g_ApplicationRunning is set to false when exiting the window.
An educated guess would be that this loop is here to facilitate easy application restarts, when e.g. changing to fullscreen or whatnot.

@prodskimaya
Copy link

It's because the while loop is "paused" while the run() function is being called. When the run() function is completed, then the app is deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants