Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix texture resource reload bug #28761

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,7 @@ Ref<Image> RasterizerStorageGLES2::texture_get_data(RID p_texture, int p_layer)

for (int i = 0; i < texture->mipmaps; i++) {

int ofs = 0;
if (i > 0) {
ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, i - 1);
}
int ofs = Image::get_image_mipmap_offset(texture->alloc_width, texture->alloc_height, real_format, i);

if (texture->compressed) {
glPixelStorei(GL_PACK_ALIGNMENT, 4);
Expand Down
5 changes: 1 addition & 4 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,10 +1210,7 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer)

for (int i = 0; i < texture->mipmaps; i++) {

int ofs = 0;
if (i > 0) {
ofs = Image::get_image_data_size(texture->alloc_width, texture->alloc_height, real_format, i - 1);
}
int ofs = Image::get_image_mipmap_offset(texture->alloc_width, texture->alloc_height, real_format, i);

if (texture->compressed) {

Expand Down
17 changes: 8 additions & 9 deletions scene/resources/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ void ImageTexture::reload_from_file() {
Ref<Image> img;
img.instance();

Error err = ImageLoader::load_image(path, img);
ERR_FAIL_COND(err != OK);

create_from_image(img, flags);
if (ImageLoader::load_image(path, img) == OK) {
create_from_image(img, flags);
} else {
Resource::reload_from_file();
_change_notify();
}
}

bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
Expand Down Expand Up @@ -638,7 +640,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
bool mipmaps = df & FORMAT_BIT_HAS_MIPMAPS;

if (!mipmaps) {
int size = Image::get_image_data_size(tw, th, format, 0);
int size = Image::get_image_data_size(tw, th, format, false);

PoolVector<uint8_t> img_data;
img_data.resize(size);
Expand All @@ -660,7 +662,6 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
int mipmaps2 = Image::get_image_required_mipmaps(tw, th, format);
int total_size = Image::get_image_data_size(tw, th, format, true);
int idx = 0;
int ofs = 0;

while (mipmaps2 > 1 && p_size_limit > 0 && (sw > p_size_limit || sh > p_size_limit)) {

Expand All @@ -670,9 +671,7 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &tw_
idx++;
}

if (idx > 0) {
ofs = Image::get_image_data_size(tw, th, format, idx - 1);
}
int ofs = Image::get_image_mipmap_offset(tw, th, format, idx);

if (total_size - ofs <= 0) {
memdelete(f);
Expand Down