`Image` constructor does not use the passed spec

Summary

When calling Image::Image(RootObject* root, const ImageBufferSpec& spec), the created image's spec does not match the passed in spec. This might lead to issues with reading OpenGL textures into the CPU side image as the allocated buffer might not fit the texture's data.

How to reproduce ?

The following snippet should be enough to demonstrate the bug:

auto img = std::make_shared<Image>(_root, spec); 
assert(spec.getRawSize() == img->getSpec().getRawSize()); // Fails
assert(spec.width == img->getSpec().width); // Fails
assert(spec.height == img->getSpec().height); // Fails

Expected behavior

(Describe here the expected behavior if this bug was not present.) The created image should use the given spec, matching the width, height, and raw buffer size.

What is the frequency of occurrence of this behavior ?

This issue occurs with every invocation of the specified constructor.

Other comment

The main cause of this bug is due to the following:

  1. Constructing a default Image::_image, no spec is passed.
  2. Creating a default 128x128 RGBA image/spec and storing it into Image::_bufferImage.
  3. Calling Image::update, which swaps Image::_image and Image::_bufferImage.

Whenever Image::getSpec is called, _image->spec is returned. By following the 3 steps above, we can see that the default spec is returned instead of the one passed in the constructor.