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

Fix to free(): invalid pointer: #45 #49

Open
gedeschaines opened this issue Aug 1, 2022 · 0 comments
Open

Fix to free(): invalid pointer: #45 #49

gedeschaines opened this issue Aug 1, 2022 · 0 comments

Comments

@gedeschaines
Copy link

Fixes to prevent Policy warnings from syntax errors in CMake code files.

  1. File: ./cmake/FindGLEW.cmake
    insert: SET(PROGRAMFILESX86 "PROGRAMFILES(X86)")
    before: SET( GLEW_SEARCH_PATHS
    and
    change: "$ENV{PROGRAMFILES(X86)}/GLEW"   # WINDOWS
        to: "$ENV{${PROGRAMFILESX86}}/GLEW"     # WINDOWS
  1. File: ./cmake/FindSDL2.cmake
    insert: SET(PROGRAMFILESX86 "PROGRAMFILES(X86)")
    before: SET( SDL2_SEARCH_PATHS
    and
    change: "$ENV{PROGRAMFILES(X86)}/SDL2"     # WINDOWS
        to: "$ENV{${PROGRAMFILESX86}}/SDL2"   # WINDOWS
  1. File: ./cmake/FindASSIMP.cmake
    insert: SET(PROGRAMFILESX86 "PROGRAMFILES(X86)")
    before: SET( ASSIMP_SEARCH_PATHS
    and
    change: "$ENV{PROGRAMFILES(X86)}/ASSIMP"	# WINDOWS
        to: "$ENV{${PROGRAMFILESX86}}/ASSIMP"	# WINDOWS

Fixes to prevent program execution abort on free(): invalid pointer.

  1. File: ./src/rendering/texture.h, line 60
    from: void operator=(Texture texture);
      to: Texture& operator=(Texture other) noexcept;
  1. File: ./src/rendering/texture.cpp, lines 207-213

    replace:

    void Texture::operator=(Texture texture)
    {
        char* temp[sizeof(Texture)/sizeof(char)];
        memcpy(temp, this, sizeof(Texture));
	memcpy(this, &texture, sizeof(Texture));
        memcpy(&texture, temp, sizeof(Texture));
    }
  with:
    Texture& Texture::operator=(Texture other) noexcept
    {
        //Implemented using move assignment.
    
        //Guard self assignment
        if (this == &other)
            return *this;
    
        if(m_textureData && m_textureData->RemoveReference())
	{
            if(m_fileName.length() > 0)
                s_resourceMap.erase(m_fileName);
	    
	        delete m_textureData;
	}
	m_fileName = other.m_fileName;
        m_textureData = other.m_textureData;
        m_textureData->AddReference();
        return *this;
    }

Originally posted by @gedeschaines in #45 (comment)

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

1 participant