aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-10-20 18:41:10 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-10-20 18:41:10 +0200
commitc8ed49929322f0e278cbce650b3903fc8dd16b60 (patch)
treecfffda8293bcf4fbb0e7261189b454ec50a5d564
parent9f609dd740f3c44d44fd377351c82edbe936911a (diff)
image: add panic when load is called without any registered loaders
-rw-r--r--core/image/general.odin10
1 files changed, 9 insertions, 1 deletions
diff --git a/core/image/general.odin b/core/image/general.odin
index 17a8f35ea..f12b6410b 100644
--- a/core/image/general.odin
+++ b/core/image/general.odin
@@ -23,7 +23,15 @@ register :: proc(kind: Which_File_Type, loader: Loader_Proc, destroyer: Destroy_
load_from_bytes :: proc(data: []byte, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
loader := _internal_loaders[which(data)]
if loader == nil {
- return nil, .Unsupported_Format
+
+ // Check if there is at least one loader, otherwise panic to let the user know about misuse.
+ for a_loader in _internal_loaders {
+ if a_loader != nil {
+ return nil, .Unsupported_Format
+ }
+ }
+
+ panic("image.load called when no image loaders are registered. Register a loader by first importing a subpackage (eg: `import \"core:image/png\"`), or with image.register")
}
return loader(data, options, allocator)
}