ImageCache can't find image


#1

ImageCache can’t find the image I want to use with it even though I’m passing it the correct path and finlename:

image = ImageCache::getFromFile(File(“C:/MyDocuments/SourceCode/cabbage/cabbage/src/images/splash.jpg”));

I’ve checked the path and file name over and over and it’s valid yet getFromFile() keep returning NULL. Any ideas?


#2

Erm, try using backslashes?


#3

hmmm… I do alot of cross platform stuff at work, where we use / as the path separator on all platforms (Windows/Linux/FreeBSD)… I’m not saying that isn’t the problem here, but it hasn’t been my experience.


#4

Hmm, true, the File constructor will probably sort the slashes out for you.

The quickest way to find out why it’s not working is to USE YOUR DEBUGGER! Don’t just stare at it, wondering what’s happening, get in there and see what it’s doing!


#5

I’m afraid my dubugging skills aren’t great apart from basic stuff. The problem is that I don’t know where to start, nothing crashes, the function getFromFile() just returns null, presumably because something is stopping it from finding the file. I’m all ears and open to suggestions about how best to debug it?


#6

Just step into it, and follow the action - you’ll see it trying to load the file, and it should be obvious what’s happening.


#7

When I step into ImageCache::getFromFile() I get taken to

void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)

the first test in there fails, i.e.,

if (dest != (void*) source || destBytesPerSample <= 4)

then it take me back to my “splashImage = ImageCache::getFromFile(file);//File(pathTomage)” I then do a if(!splashImage) do something, and something always happens. No matter how I step through it with the debugger I never get to any ImageCache methods? My doe couldn’t be simpler:

File file(“C:/MyDocuments/SourceCode/cabbage/cabbage/src/images/splash.jpg”);
splashImage = ImageCache::getFromFile(file);//File(pathTomage)
if(splashImage)
{
do somethings…
}


#8

try

File file(whatever_path);

if (file.existsAsFile())
{
 Logger::writeToLog (T("file exists and is valid, size is") + String(file.getSize()) );
}
else
{
 Logger::writeToLog (T("file is not htere, someone stole it"));
}

this way you can verify if your path is fine and if you can fetch any info on that file.


#9

I bet you’re using the big amalgamated cpp file in visual studio. There’s a bug in their debugger that gets the line numbers wrong - try including juce_amalgamated_template.cpp instead and you can debug with no trouble.


#10

I’m just getting back to this now. I’ve added juce_amalgamated_template.cpp and now the debugger takes me to where I need to go. This is the function from juce_ImageCache.cpp. Going through it in the debugger hasn’t helped me at all. Here’s the low down. It gets to this function(below), everything is fine, image is not 0 so it enters if() section. ImageFileFormat if fine in so far as it passes all the tests checking if it’s a valid object. Then the oddness takes place, even though loadFile() returns a valid object addImageToCache() doesn’t see image as a valid object. The first thing addImageToCache() does is check that image is ok and it’s not. I don’t know why.

Image* ImageCache::getFromFile (const File& file)
{
const int64 hashCode = file.hashCode64();
Image* image = getFromHashCode (hashCode);

if (image == 0)
{
    image = ImageFileFormat::loadFrom (file);
    addImageToCache (image, hashCode);
}

return image;

}

I’ve tried lots of different image format but none of them work.


#11

Can you drop the file into the jucer as a graphics object? If so, then it can load it fine and you’ve got the path wrong. If not, then I guess the format’s not supported.


#12

I must be losing my mind, I had the the wrong path, please delete this thread and save me from the embarrassment!