Skip to content

Commit

Permalink
Merge pull request #443 from GustJc/fix-warnings
Browse files Browse the repository at this point in the history
Fix 'loaded resource as image file' warnings
  • Loading branch information
Zylann authored May 16, 2024
2 parents 0d26337 + 9e9138f commit fbb9e5d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions addons/zylann.hterrain/hterrain_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1392,9 +1392,9 @@ func _load_map(dir: String, map_type: int, index: int, resource_loader_cache_mod
# But in the editor we want textures to be editable,
# so we have to automatically load the data also in RAM
if map.image == null:
map.image = Image.load_from_file(fpath)
map.image = Image.load_from_file(ProjectSettings.globalize_path(fpath))
else:
map.image.load(fpath)
map.image.load(ProjectSettings.globalize_path(fpath))
_ensure_map_format(map.image, map_type, index)

if map_type == CHANNEL_HEIGHT:
Expand Down Expand Up @@ -1466,7 +1466,7 @@ func _import_heightmap(fpath: String, min_y: float, max_y: float, big_endian: bo
# Godot can only load 8-bit PNG,
# so we have to bring it back to float in the wanted range

var src_image := Image.load_from_file(fpath)
var src_image := Image.load_from_file(ProjectSettings.globalize_path(fpath))
# TODO No way to access the error code?
if src_image == null:
return false
Expand Down Expand Up @@ -1509,7 +1509,7 @@ func _import_heightmap(fpath: String, min_y: float, max_y: float, big_endian: bo
_logger.error(str("Invalid heightmap format ", im.get_format()))

elif ext == "exr":
var src_image := Image.load_from_file(fpath)
var src_image := Image.load_from_file(ProjectSettings.globalize_path(fpath))
# TODO No way to access the error code?
if src_image == null:
return false
Expand Down Expand Up @@ -1696,7 +1696,7 @@ func _import_map(map_type: int, path: String) -> bool:
# Heightmap requires special treatment
assert(map_type != CHANNEL_HEIGHT)

var im := Image.load_from_file(path)
var im := Image.load_from_file(ProjectSettings.globalize_path(path))
# TODO No way to get the error code?
if im == null:
return false
Expand Down
2 changes: 1 addition & 1 deletion addons/zylann.hterrain/tools/brush/brush.gd
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func is_shape_cycling_enabled() -> bool:

static func load_shape_from_image_file(fpath: String, logger, retries := 1) -> Texture2D:
var im := Image.new()
var err := im.load(fpath)
var err := im.load(ProjectSettings.globalize_path(fpath))
if err != OK:
if retries > 0:
# TODO There is a bug with Godot randomly being unable to load images.
Expand Down
2 changes: 1 addition & 1 deletion addons/zylann.hterrain/tools/importer/importer_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static func _load_image_size(path: String, logger, bit_depth: int) -> HT_ImageSi
if ext == "png" or ext == "exr":
# Godot can load these formats natively
var im := Image.new()
var err := im.load(path)
var err := im.load(ProjectSettings.globalize_path(path))
if err != OK:
logger.error("An error occurred loading image '{0}', code {1}".format([path, err]))
result.error_code = err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static func generate_image(sources: Dictionary, resolution: int, logger) -> HT_R
else:
# File
src_image = Image.new()
var err := src_image.load(src_path)
var err := src_image.load(ProjectSettings.globalize_path(src_path))
if err != OK:
return HT_Result.new(false, "Could not open file \"{0}\": {1}" \
.format([src_path, HT_Errors.get_message(err)])) \
Expand Down
2 changes: 1 addition & 1 deletion addons/zylann.hterrain/tools/preview_generator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func _generate_from_path(path: String, size: Vector2i, metadata: Dictionary) ->
var normals_fname := str(HTerrainData.get_channel_name(HTerrainData.CHANNEL_NORMAL), ".png")
var normals_path := data_dir.path_join(normals_fname)
var normals := Image.new()
var err := normals.load(normals_path)
var err := normals.load(ProjectSettings.globalize_path(normals_path))
if err != OK:
_logger.error("Could not load '{0}', error {1}" \
.format([normals_path, HT_Errors.get_message(err)]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func _set_ui_slot_texture_from_path(im_path: String, type: int):
else:
# Regular path
im = Image.new()
var err := im.load(im_path)
var err := im.load(ProjectSettings.globalize_path(im_path))
if err != OK:
_logger.error(str("Unable to load image from ", im_path))
# TODO Different icon for images that can't load?
Expand Down
2 changes: 1 addition & 1 deletion addons/zylann.hterrain/tools/util/editor_util.gd
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static func load_texture(path: String, logger) -> Texture:
# See https://github.com/godotengine/godot/issues/17483
logger.error(str("Failed to load texture ", path, ", attempting to load manually"))
var im := Image.new()
var err = im.load(path)
var err = im.load(ProjectSettings.globalize_path(path))
if err != OK:
logger.error(str("Failed to load image ", path))
return null
Expand Down

0 comments on commit fbb9e5d

Please sign in to comment.