Compare surfaces?

How would i go about comparing surfaces?
I’m trying to check whether an image has been modified after a certain amount of time purely based on the assumption that the raw data will be the same, to avoid having to check each pixel in each image. I’ve tried comparing &SurfaceX != &SurfaceY but that doesn’t seem to work,
neither does SurfaceX.getData() != surfaceY.getData()

mOrigImage has the same image stored prior to this and has not been modified since.
mSourceFileName is a string that holds the path of the image

why isn’t Surface temp equal to mOrigImage?

if (mSourceFileName != ""){
            Surface temp = loadImage(mSourceFileName);
            console() << &temp << std::endl;
            console() << &mOrigImage << std::endl;
                if (&temp != &mOrigImage){
                    mSourceImage = mOrigImage;


What are you trying to do exactly? Comparing surfaces could be done by checking all pixels in the surface and searching for changed pixel values.

If you would like to detect whether an image file has been changed since last read, it can be done by checking the file access times. @Simon’s Watchdog is perfect for this task.


My goal is to check if the my imported image has been modified, for example if I’ve minimized the program or had it out of focus. if true, then reload the image again. I know it can be done by checking each pixel in the image but it seems to me that, that would be more cpu demanding than for example reloading the image once in a while or make a timer or similar.

Checking the access time sounds like a good way to do it too, however if it can be done without adding more header files, then I would prefer that.

You can check if the file was modified by calling fs::last_write_time( path ).

This is from boost. This is how Watchdog does it:

Boost reference:

Ah that looks good, I’ll check that out.
Thanks :wink: