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

Question about GWork object destruction order #23

Closed
Grant1219 opened this issue Jun 9, 2016 · 3 comments
Closed

Question about GWork object destruction order #23

Grant1219 opened this issue Jun 9, 2016 · 3 comments

Comments

@Grant1219
Copy link
Contributor

I am currently trying to use GWork within a singleton class like the following:

    class GuiManager {
        public:
            // NOTE: allegro *must* be initialized for these to work
            static Gwk::Controls::Canvas* GetCanvas() {
                return GetInst().gwk_canvas;
            }

            static Gwk::Input::Allegro* GetInput() {
                return GetInst().gwk_input;
            }

        private:
            static GuiManager& GetInst() {
                static GuiManager gui_inst;
                return gui_inst;
            }

            GuiManager() {
                // this is why allegro must be initialized
                ALLEGRO_DISPLAY* display = al_get_current_display();

                Gwk::Platform::SetPlatformWindow(display);

                gwk_renderer = new Gwk::Renderer::Allegro();
                gwk_skin = new Gwk::Skin::TexturedBase(gwk_renderer);
                gwk_skin->SetRender(gwk_renderer);
                gwk_skin->Init("data/DefaultSkin.png");
                gwk_skin->SetDefaultFont("data/OpenSans.ttf", 11);

                gwk_canvas = new Gwk::Controls::Canvas(gwk_skin);
                gwk_canvas->SetSize(al_get_display_width(display),
                                    al_get_display_height(display));
                gwk_canvas->SetDrawBackground(true);
                gwk_canvas->SetBackgroundColor(Gwk::Color(94, 127, 181, 255));
                gwk_input = new Gwk::Input::Allegro();
                gwk_input->Initialize(gwk_canvas);
            }

            Gwk::Renderer::Allegro* gwk_renderer;
            Gwk::Skin::TexturedBase* gwk_skin;
            Gwk::Controls::Canvas* gwk_canvas;
            Gwk::Input::Allegro* gwk_input;
    };

This is causing an error on program termination:
*** Error in./client': corrupted double-linked list: 0x000000000139cd40 ***`

I believe this is caused by the non-deterministic deletion order when the singleton members are destructed.
Is there a correct order to follow for manual deletion of these GWork instances?
Currently if I try to delete them I am getting a segfault.

Thanks in advance.

@Grant1219
Copy link
Contributor Author

This error has stopped happening after a complete clean and rebuild, but my question is still valid about the correct order for deleting GWork objects.

@billyquith
Copy link
Owner

This is related to #7.

@Grant1219
Copy link
Contributor Author

Cool thanks, I did some looking into the destructors of the Control classes and it seems like they do some cleanup, such as deleting all child elements.
https://github.com/billyquith/GWork/blob/gwork/source/gwork/source/Controls/Base.cpp#L69-L81

I'll keep looking into it when I have time. Closing this for now.

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

2 participants