EBZ said:
Regarding if I'm using mutexes, I am. Making sure I'm locking that thread until it's done. And you're right, I got my terminology completely wrong, I actually got a runtime error.
Can you show us the runtime-errors you are getting then? Would be really helpful, because I'm not seing anything actually wrong with the code you just showed.
Sorry about the dumb questions but you're suggesting to use: std::vector<std::unique_ptr<char[]>> images.
When I'm pushing into the vector, what would it look like: images.push(std::make_unique<char[]>(data)); and then loaded in like:
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, images[i]); ?
Yeah, like that. I mean, now that I have seen your code I'm not sure how well that would work in your case, since that data returned by stbi_load I assume would have to be deleted by something like stbi_destory, no? In that case you could still use an std::unique_ptr<char*, CustomDeleter>, but yeah it would be a little more work
Other than that, there are probably just some read flags in your code:
- You are creating “Texture texture” on the stack, then create a shared-ptr by copying that object and putting that into a container. You should std::move the texture-object, otherwise you are at the very least wasting performance. In the worse case, if Texture has a destructor that clears that owned data, that would explain why you are getting errors since the local variables ~Texture-destructor would run, and since the vector of data has not been moved it would invoke delete on the data.
- Why are you even using an shared_ptr? Is there any shared ownership of the Texture-proxy object later on? If this is your final texture object, I think it is better if you instead created a local proxy just for loading and fully create the texture later on; which should then be eigther an std::unique_ptr; or even better just std::vector<TextureProxy>. Unless you really do intend on using dataPayload later on after the texture is loaded, but if I assume correctly and this is just for loading; it should not be part of your final Texture-class.