Skip to content

Imagereader error reporting & handling#3150

Open
iommu wants to merge 1 commit into
f3d-app:masterfrom
iommu:image_report_errors
Open

Imagereader error reporting & handling#3150
iommu wants to merge 1 commit into
f3d-app:masterfrom
iommu:image_report_errors

Conversation

@iommu

@iommu iommu commented May 14, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

In normal f3d usage, Imagereader failing to read a file would result in silenced errors and produce a un-intialized buffer. E.g. f3d --no-config --force-reader=PNG f3d.glb results in :

  • No visible warnings in the GUI (or CLI if run from a terminal)
  • A corrupted image (square, usually red or sometimes random text could be seen)

Note : this behaviour would change if --verbose was specified to the command line f3d --no-config --force-reader=PNG f3d.glb --verbose and warnings would be visible in the CLI and GUI, however the corrupted image would still appear.

I have implemented 2 main changes to improve this.

  1. When vtkF3DImageImporter is trying to import an image it will check if the reader called UpdateInformation() correctly and also check if the error codes were set on reader reader->GetErrorCode() != 0.

  2. When the f3d::scene is trying to first add the image importer to the list of importers we check if reader->canRead(...) returns successful.

  • If unsuccessful & running with default verbosity an error is thrown* which specifies the user can use the --verbose flag for more information.

  • If unsuccessful & running with verbosity == debug then a warning is thrown but the code will continue on like it used to**.

* should we throw an error or simply print a debug line? It seems a lot of similar code in this file throws an error e.g. if f3d couldn't find a reader for the file type specified. But this implies that one bad file in a batch import can throw the entire scene correct?
** as canRead() generally does not provide any VTK errors as to why an image failed, a debug option (locked behind verbosity == debug) is provided which will continue on to run the code listed above and will print any VTK errors provided by the reader.

Before any changes

f3d --no-config --force-reader=PNG ./testing/data/f3d.glb
# No errors printed, but random image displayed

After change 1

f3d --no-config --force-reader=PNG ./testing/data/f3d.glb
Some of these files could not be loaded: failed to load scene
  /home/iommu/Desktop/f3d/testing/data/f3d.glb
# Error (as shown ^^^) is printed to terminal and to GUI "!" and no image is displayed

After change 2

f3d --no-config --force-reader=PNG ./testing/data/f3d.glb
Some of these files could not be loaded: /home/iommu/Desktop/f3d/testing/data/f3d.glb could not be read by the forced reader "PNG" , use the --verbose command flag for more information
  /home/iommu/Desktop/f3d/testing/data/f3d.glb
# Error (as shown ^^^) is printed to terminal and to GUI "!" and no image is displayed 

After change 2 : verbose

f3d --no-config --force-reader=PNG ./testing/data/f3d.glb --verbose
... normal debug logs...
Checking files:
Forcing reader PNG for /home/iommu/Desktop/f3d/testing/data/f3d.glb
The reader "PNG" is reporting it cannot read the file "/home/iommu/Desktop/f3d/testing/data/f3d.glb".

Loading files: 
/home/iommu/Desktop/f3d/testing/data/f3d.glb

ERROR: In vtkPNGReader.cxx, line 161
vtkPNGReader (0x560203fa7040): Unknown file type! Not a PNG file!

ERROR: In vtkPNGReader.cxx, line 338
vtkPNGReader (0x560203fa7040): Invalid file header: not a PNG file

ERROR: In vtkExecutive.cxx, line 729
vtkCompositeDataPipeline (0x560204074ba0): Algorithm vtkPNGReader (0x560203fa7040) returned failure for request: vtkInformation (0x560204076840)
  Debug: Off
  Modified Time: 16406
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0

ERROR: In vtkF3DImageImporter.cxx, line 58
vtkF3DImageImporter (0x560203fa66d0): Reader failed to read the image

Some of these files could not be loaded: failed to load scene
  /home/iommu/Desktop/f3d/testing/data/f3d.glb
# Error (as shown ^^^) is printed to terminal and to GUI "!" and no image is displayed 

Issue ticket number and link if any

#2929

Checklist for finalizing the PR

  • I have performed a self-review of my code
  • I have added tests for new features and bugfixes
  • I have added documentation for new features
  • If it is a modifying the libf3d API, I have updated bindings
  • If it is a modifying the .github/workflows/versions.json, I have updated docker_timestamp

AI Disclosure

  • I did not use AI to generate any of the content of that pull request
  • I used AI to generate code in that pull request, if yes please disclose which part of the code was generated and with which model.
  • AI was used for research purposes for debugging only and all relevant code was deleted for this PR. (Model was the default google one that pops up when you search things)

Continuous integration

Fail if either of these is not correct, this ensures a random data image will not be loaded
@iommu
iommu requested a review from a team as a code owner May 14, 2026 00:29
@iommu

iommu commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

The initial issue was a little vague with what exactly it wanted from a fix. So I've just taken a look at what is currently possible without modifying VTK.

Ideally, if the VTK source could be changed so that the canReadFile function prints errors and is guaranteed to perform the same checks that a normal import provides then we could disable the --verbosity code I've added for this PR.

But if you have any changes you'd like then I can take a look at those too.

@mwestphal

Copy link
Copy Markdown
Member

if the VTK source could be changed so that the canReadFile function prints errors

Definitly not what we want, because VTK errors should be locked behind --verbose anyway

change 1 vs change 2

I did not look at the code yet, but all other reader behave like change 1 and I think this is enough.
Loading multiple files is a fairly limited usecase multi-file-mode and if i remember correctly, being more precise required a deeper rework that did not looked great.

@mwestphal mwestphal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answered some questions; feel free to request another review when needed

@iommu

iommu commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Definitly not what we want, because VTK errors should be locked behind --verbose anyway

Sorry, by "prints errors" I meant it should emit the same VTKErrors (or maybe warnings?) when the CanReadFile function is called.
e.g. for vtkPNGReader

vtkNew<vtkPNGReader> reader;
reader->SetFileName("abc.notpng");
reader->Update(); // Emits an error about invalid header

reader->CanReadFile("abc.notpng"); // TODO : Should also emit error about invalid header

This has no current ramifications for F3D, but it would mean for a VTK programmer, if they do use code like

if (!reader->CanReadFile(file) {
exit(0);
}

Then a user can get valid debug information by turning on VTK error printing.

Relevant code where you can see debug info printed, vs not printed.
CanReadFile, Update


Back to this PR though, yes sure I can remove change 2 if you'd like. Would you like me to add the message telling users about using --verbose? or maybe just a message specifying which file failed? (sorry about the delay btw, subnautica 2 just came out haha)

@mwestphal

Copy link
Copy Markdown
Member

Unless I'm mistaken, reader->CanReadFile("abc.notext") is not supposed to print anything, at least thats how I implemented most of them.

Would you like me to add the message telling users about using --verbose?

Thats not necessary

or maybe just a message specifying which file failed?

Im not against that but it would have to be generic for all formats, not just images. But I think this is a different issue witha a different fix.

@mwestphal

Copy link
Copy Markdown
Member

sorry about the delay btw, subnautica 2 just came out haha

No worries, enjoy :)

@iommu
iommu force-pushed the image_report_errors branch from 53a80e2 to 44dd75b Compare May 28, 2026 13:58
@mwestphal mwestphal linked an issue May 28, 2026 that may be closed by this pull request
@mwestphal

Copy link
Copy Markdown
Member

Need any help moving forward @iommu ? :)

1 similar comment
@mwestphal

Copy link
Copy Markdown
Member

Need any help moving forward @iommu ? :)

@iommu

iommu commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Ah! Hi, so sorry, I got very sidetracked.

Ah yes last I modified this I believe it should do what you requested it should :)
So I rolled back the changes I added that would fail based on CanReadFile() 's output and so now it should safely error out if reader fails while attempting to read.

If you have any specific changes beyond this I can take a look into it, but at the moment I believe this should do what you're intending it should.

@mwestphal
mwestphal self-requested a review July 6, 2026 12:25

@mwestphal mwestphal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please add a test though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Readers do not report errors properly

2 participants