DucktapeEngine / Ducktape

Ducktape - An open source 3d C++ game engine.
MIT License
127 stars 25 forks source link

Null pointers not handled #154

Closed LordRibblesdale closed 2 years ago

LordRibblesdale commented 2 years ago

Describe the bug In Entity.h "Assign" and "Remove", the code doesn't handle null pointers, in cases of no registers found

Additional context "RegisterFunc assignFunc" is the returned register from a dynamic library. If not found, the pointer is null and, even if checked, the related functions don't exit

        Component *Assign(const std::string &name)
        {
#ifdef _WIN32
            RegisterFunc registerFunc = (RegisterFunc)GetProcAddress(scene->gameModule, ("Register" + name).c_str());
#endif
#ifdef __linux__
            RegisterFunc registerFunc = (RegisterFunc)dlsym(scene->gameModule, ("Register" + name).c_str());
#endif
            if (!registerFunc)
            {
                std::cout << "Failed to get REGISTER(" << name << ") function from Game Module." << std::endl;
            }

            Component *component = (*registerFunc)(*this, scene, scene->initializedComponents, RegisterAction::Assign);

            (*registerFunc)(*this, scene, false, RegisterAction::AddSystem);

            return component;
        }
        void Remove(const std::string &name)
        {
#ifdef _WIN32
            RegisterFunc assignFunc = (RegisterFunc)GetProcAddress(scene->gameModule, ("Register" + name).c_str());
#endif
#ifdef __linux__
            RegisterFunc assignFunc = (RegisterFunc)dlsym(scene->gameModule, ("Register" + name).c_str());
#endif
            if (!assignFunc)
            {
                std::cout << "Failed to get REGISTER(" << name << ") function from Game Module." << std::endl;
            }

            (*assignFunc)(*this, scene, false, RegisterAction::Remove);
        }