c++stringimagemagickmagick++

ImageMagick Error: Unable to open image


I'm using ImageMagick (Magick++) in my application but when trying to load an image I get the error:

Unable to open image '??': Invalid argument @ error/blob.c/OpenBlob/2657

From reading other peoples problems online ?? is typically the file trying to be loaded, and I am obviously not passing the file location ?? to the loader - so it appears not to be able to resolve the string I am giving it. Tried using Unicode and Multi-byte. Copied project settings from example(s). File definitely exists and definitely the correct location.

Code:

LawlessFBXTexture* LawlessFBXTextureManager::CreateTexture(std::string pFullFilePath) 
{
    Magick::Image* img = nullptr;
    Magick::Blob blob;

    try
    {
        img = new Magick::Image();
        img->read(pFullFilePath);
        img->write(&blob, "RGBA");
    }
    catch (Magick::Error& Err)
    {
        std::string errstr = Err.what();
        std::wstring stemps = std::wstring(errstr.begin(), errstr.end());
        LPCWSTR sws = stemps.c_str();
        OutputDebugString(L"FBXSDK: ERROR: ");
        OutputDebugString(sws);
        OutputDebugString(L"\n");

        int ImageNotFound = 0;      /// Image Not found <---
        assert(ImageNotFound);
    }

    LawlessFBXTexture* tex = new LawlessFBXTexture();

    glGenTextures(1, &tex->TextureBuffer);
    glBindTexture(GL_TEXTURE_2D, tex->TextureBuffer);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->columns(), img->rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blob.data());
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    return tex;
}

being called by :

LawlessFBXTexture* tex = CreateTexture("..\\..\\Asset\\Models\\LawlessCoreAsset\\DEFAULT_DIFFUSE.png");


Solution

  • I noticed this works fine in release mode, without making changes. I am pretty sure this is down to a bug so I'll post my findings on the Magick forums.