Fix cubemap face loading: direct HTTP + array-wrapped pending counter

- Remove ContentCache.load_texture_async for cubemap faces; ImageTexture.get_image()
  silently returns null in some Godot 4 builds, leaving all images[] null
- Fetch each face directly with HTTPRequest (same pattern as _load_static_skybox),
  keeping raw Image objects — no GPU round-trip
- Wrap `pending` in Array[1] so closures always capture a reference, not a
  stale copy of the int (GDScript 4 primitive closure-capture is unreliable)
- Log warning per face on download or decode failure

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-25 18:47:27 -04:00
co-authored by Claude Happy
parent 83a4346824
commit 70f0089b2f
@@ -547,21 +547,46 @@ func _load_cubemap_skybox(skybox: Dictionary) -> void:
]
var images: Array = []
images.resize(6)
var pending := 6
# Wrap pending in an Array so closures capture the container (always a reference),
# avoiding GDScript's unreliable primitive-int capture across async callbacks.
var pending := [6]
for i in 6:
var idx := i
var url : String = urls[idx]
if url.is_empty():
images[idx] = null
pending -= 1
if pending == 0:
pending[0] -= 1
if pending[0] == 0:
_apply_cubemap_images(images)
continue
ContentCache.load_texture_async(url, func(tex: Texture2D):
images[idx] = tex.get_image() if tex != null else null
pending -= 1
if pending == 0:
# Download face image directly — avoids ImageTexture.get_image() round-trip
# which can silently return null in some Godot 4 builds.
var http := HTTPRequest.new()
add_child(http)
http.request_completed.connect(func(_res: int, code: int, _hdrs: PackedStringArray, data: PackedByteArray):
http.queue_free()
if code >= 200 and code < 300 and not data.is_empty():
var img := Image.new()
var ext := url.split("?")[0].get_extension().to_lower()
var load_err: Error
if ext in ["jpg", "jpeg"]:
load_err = img.load_jpg_from_buffer(data)
elif ext == "webp":
load_err = img.load_webp_from_buffer(data)
else:
load_err = img.load_png_from_buffer(data)
if load_err == OK:
images[idx] = img
else:
push_warning("[GameScreen] Cubemap face %d decode failed (ext=%s)" % [idx, ext])
images[idx] = null
else:
push_warning("[GameScreen] Cubemap face %d download failed: HTTP %d" % [idx, code])
images[idx] = null
pending[0] -= 1
if pending[0] == 0:
_apply_cubemap_images.call_deferred(images))
http.request(url)
func _apply_cubemap_images(raw: Array) -> void:
# Convert to typed array — create_from_images() requires Array[Image].