Bug 409552

Summary: Krita can save an EXR image it cannot open again
Product: [Applications] krita Reporter: Bence Mihaly <se.wrath6>
Component: GeneralAssignee: Halla Rempt <halla>
Status: RESOLVED FIXED    
Severity: crash CC: halla
Priority: NOR    
Version: 4.2.2   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Bence Mihaly 2019-07-06 14:05:10 UTC
SUMMARY
An image I was working on has begun failing to load entirely and crashes Krita whenever I attempt to open the aforementioned image file. The issue does not carry over to any other images I have worked on in the past.

Reproducible: Always

STEPS TO REPRODUCE
1. Load Krita up
2. select image

OBSERVED RESULT
A window appears stating that the image has been modified so that the pixels have some alpha values (this is normal and happened before the issue) then the application seemingly loads before closing entirely.

EXPECTED RESULT
The mentioned window about the alpha values appears and the image loads and allows additional changes to be made.

Request: Should the issue not be a direct bug or is otherwise not fixable (e.g: the file itself is corrupted), I would like to know if there is any way to restore the file or recover any past saves of the file.
Comment 1 Halla Rempt 2019-07-06 14:09:12 UTC
Please provide the file so we can take a look at it -- a dropbox link or google drive link or something like that. 

For recovery, check whether there are backup files for this file that do load (they end in .kra~, and you might have to tell Windows Explorer to show file extensions to see this.)

Please also consider the save incremental version feature for important work.
Comment 2 Bence Mihaly 2019-07-06 14:57:58 UTC
(In reply to Boudewijn Rempt from comment #1)
> Please provide the file so we can take a look at it -- a dropbox link or
> google drive link or something like that. 
> 
> For recovery, check whether there are backup files for this file that do
> load (they end in .kra~, and you might have to tell Windows Explorer to show
> file extensions to see this.)
> 
> Please also consider the save incremental version feature for important work.

I attempted to open the backup file but it crashed Explorer. I am not sure if the issue has anything to do with the fact that I saved the image as a .EXR file but this has not caused any sort of problems with previous works.

The link to the file: https://drive.google.com/file/d/12q1chNJDl8PbfOzDnXWIgGsuSNOAWw-H/view?usp=sharing_eil&ts=5d20b637
Comment 3 Halla Rempt 2019-07-06 15:03:23 UTC
Okay, I've requested access as vurian@gmail.com . Is this ifile also an exr file?
Comment 4 Bence Mihaly 2019-07-06 15:24:41 UTC
Yes it should be, I’ve saved everything related to the file as .exr.
Comment 5 Halla Rempt 2019-07-06 15:34:33 UTC
Hm, that might make it harder. It's generally best to work in .kra files, and only export to exr or other formats when needed. I still don't have access to the link, though.
Comment 6 Halla Rempt 2019-07-06 17:16:23 UTC
Thanks, I got the file now. Other applications can still show it, but Krita asserts on it.

Backtrace:

ASSERT (krita): "layerName == layer->name()" in file /home/boud/dev/krita/plugins/impex/libkra/kis_kra_savexml_visitor.cpp, line 293


Thread 1 (Thread 0x7f74045af000 (LWP 6262)):
[KCrash Handler]
#6  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#7  0x00007f73fef7d801 in __GI_abort () at abort.c:79
#8  0x00007f73ff952f2b in QMessageLogger::fatal(char const*, ...) const () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#9  0x00007f74012ad91e in kis_assert_common (assertion=assertion@entry=0x7f73a8139978 "layerName == layer->name()", file=file@entry=0x7f73a8139900 "/home/boud/dev/krita/plugins/impex/libkra/kis_kra_savexml_visitor.cpp", line=line@entry=293, throwException=throwException@entry=false, isIgnorable=isIgnorable@entry=false) at /home/boud/dev/krita/libs/global/kis_assert.cpp:90
#10 0x00007f74012ada3a in kis_assert_recoverable (assertion=assertion@entry=0x7f73a8139978 "layerName == layer->name()", file=file@entry=0x7f73a8139900 "/home/boud/dev/krita/plugins/impex/libkra/kis_kra_savexml_visitor.cpp", line=line@entry=293) at /home/boud/dev/krita/libs/global/kis_assert.cpp:103
#11 0x00007f73a8130d5d in KisSaveXmlVisitor::loadLayerAttributes (el=..., layer=layer@entry=0x55be0180a7d0) at /home/boud/dev/krita/plugins/impex/libkra/kis_kra_savexml_visitor.cpp:293
#12 0x00007f73a8131595 in KisSaveXmlVisitor::loadPaintLayerAttributes (el=..., layer=0x55be0180a7d0) at /home/boud/dev/krita/plugins/impex/libkra/kis_kra_savexml_visitor.cpp:132
#13 0x00007f73a836f2eb in KisExrLayersSorter::Private::processLayers (this=this@entry=0x7f73d8004f20, root=...) at /home/boud/dev/krita/plugins/impex/exr/kis_exr_layers_sorter.cpp:109
#14 0x00007f73a836f33b in KisExrLayersSorter::Private::processLayers (this=this@entry=0x7f73d8004f20, root=...) at /home/boud/dev/krita/plugins/impex/exr/kis_exr_layers_sorter.cpp:115
#15 0x00007f73a836fc1f in KisExrLayersSorter::KisExrLayersSorter (this=0x7fff7f9d0a70, extraData=..., image=...) at /home/boud/dev/krita/plugins/impex/exr/kis_exr_layers_sorter.cpp:170
#16 0x00007f73a835b98f in EXRConverter::decode (this=this@entry=0x7fff7f9d0bf0, filename=...) at /home/boud/dev/krita/plugins/impex/exr/exr_converter.cc:909
#17 0x00007f73a835c7ad in EXRConverter::buildImage (this=this@entry=0x7fff7f9d0bf0, filename=...) at /home/boud/dev/krita/plugins/impex/exr/exr_converter.cc:931
#18 0x00007f73a8354497 in exrImport::convert (this=0x55bdfdb65cb0, document=0x55bdf814e370) at /home/boud/dev/krita/plugins/impex/exr/exr_import.cc:45
#19 0x00007f740329a02d in KisImportExportManager::doImport (this=this@entry=0x55bdfee48100, location=..., filter=...) at /home/boud/dev/krita/libs/ui/KisImportExportManager.cpp:601
#20 0x00007f740329b851 in KisImportExportManager::convert (this=this@entry=0x55bdfee48100, direction=direction@entry=KisImportExportManager::Import, location=..., realLocation=..., mimeType=..., showWarnings=<optimized out>, exportConfiguration=..., isAsync=<optimized out>) at /home/boud/dev/krita/libs/ui/KisImportExportManager.cpp:361
#21 0x00007f740329c15b in KisImportExportManager::importDocument (this=this@entry=0x55bdfee48100, location=..., mimeType=...) at /home/boud/dev/krita/libs/ui/KisImportExportManager.cpp:136
#22 0x00007f740328650a in KisDocument::openFile (this=this@entry=0x55bdf814e370) at /home/boud/dev/krita/libs/ui/KisDocument.cpp:1431
#23 0x00007f7403286efb in KisDocument::openUrlInternal (this=this@entry=0x55bdf814e370, url=...) at /home/boud/dev/krita/libs/ui/KisDocument.cpp:1873
#24 0x00007f74032873bf in KisDocument::openUrl (this=0x55bdf814e370, _url=..., flags=...) at /home/boud/dev/krita/libs/ui/KisDocument.cpp:1330
#25 0x00007f74032a4a4d in KisMainWindow::openDocumentInternal (this=this@entry=0x55bdfbe87ab0, url=..., flags=flags@entry=...) at /home/boud/dev/krita/libs/ui/KisMainWindow.cpp:909
#26 0x00007f74032aa87e in KisMainWindow::openDocument (this=this@entry=0x55bdfbe87ab0, url=..., flags=flags@entry=...) at /home/boud/dev/krita/libs/ui/KisMainWindow.cpp:884
#27 0x00007f74032738b8 in KisApplication::start (this=<optimized out>, args=...) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:601
#28 0x000055bdf2322d7b in main (argc=<optimized out>, argv=0x7fff7f9d1918) at /home/boud/dev/krita/krita/main.cc:513

This is really weird because the the assert happens when saving to .kra... Thanks for you report, and I'll try to figure out what's going on.
Comment 7 Bence Mihaly 2019-07-06 17:57:42 UTC
Thanks for the help.
Comment 8 Halla Rempt 2019-07-08 13:11:47 UTC
It looks like there's a problem with the layer names.
Comment 9 Halla Rempt 2019-07-08 13:13:23 UTC
The layer names as stored in the properties vs. the name of the layer as loaded are:

"Layer 1" "Layer 1_1"
"Layer 1" "Layer 1_0"
"Background paint" "Background paint"
"HDR Layer" "HDR Layer"
Comment 10 Halla Rempt 2019-07-08 13:14:47 UTC
Metadata:

boud@boud-ThinkPad-T470p:~/dev/b-krita$ exrheader ~/Downloads/Fiore\ dei\ Liberi\ Knight.exr 

file /home/boud/Downloads/Fiore dei Liberi Knight.exr:

file format version: 2, flags 0x0
channels (type chlist):
    A, 16-bit floating-point, sampling 1 1
    B, 16-bit floating-point, sampling 1 1
    Background paint.A, 16-bit floating-point, sampling 1 1
    Background paint.B, 16-bit floating-point, sampling 1 1
    Background paint.G, 16-bit floating-point, sampling 1 1
    Background paint.R, 16-bit floating-point, sampling 1 1
    G, 16-bit floating-point, sampling 1 1
    Layer 1_0.A, 16-bit floating-point, sampling 1 1
    Layer 1_0.B, 16-bit floating-point, sampling 1 1
    Layer 1_0.G, 16-bit floating-point, sampling 1 1
    Layer 1_0.R, 16-bit floating-point, sampling 1 1
    Layer 1_1.A, 16-bit floating-point, sampling 1 1
    Layer 1_1.B, 16-bit floating-point, sampling 1 1
    Layer 1_1.G, 16-bit floating-point, sampling 1 1
    Layer 1_1.R, 16-bit floating-point, sampling 1 1
    R, 16-bit floating-point, sampling 1 1
compression (type compression): zip, multi-scanline blocks
dataWindow (type box2i): (0 0) - (1753 2479)
displayWindow (type box2i): (0 0) - (1753 2479)
krita_layers_info (type string): "<!DOCTYPE krita-extra-layers-info>
<root>
 <layer colorspacename="RGBAF16" name="Layer 1" channelflags="" visible="1" filename="layer0" locked="0" colorlabel="0" opacity="255" channellockflags="" compositeop="normal" onionskin="0" x="0" intimeline="0" exr_name="Layer 1_1" collapsed="0" y="0" uuid="{f03d3cd8-9abc-4fd5-a5b7-2afb4b13a623}" nodetype="paintlayer"/>
 <layer colorspacename="RGBAF16" name="Background paint" channelflags="" visible="0" filename="layer0" locked="0" colorlabel="0" opacity="255" channellockflags="1111" compositeop="normal" onionskin="0" x="0" intimeline="0" exr_name="Background paint" collapsed="0" y="0" uuid="{dbd8565e-899c-4581-8508-e51a5222f8e6}" nodetype="paintlayer"/>
 <layer colorspacename="RGBAF16" name="HDR Layer" channelflags="" visible="1" filename="layer0" locked="0" colorlabel="0" opacity="255" channellockflags="1111" compositeop="normal" onionskin="0" x="0" intimeline="0" exr_name="HDR Layer" collapsed="0" y="0" uuid="{979def5c-af62-4bc3-b549-5bd4d1cd390e}" nodetype="paintlayer"/>
 <layer colorspacename="RGBAF16" name="Layer 1" channelflags="" visible="1" filename="layer0" locked="0" colorlabel="0" opacity="255" channellockflags="" compositeop="normal" onionskin="0" x="0" intimeline="0" exr_name="Layer 1_0" collapsed="0" y="0" uuid="{76630954-82a1-4608-9eee-76455090cdbb}" nodetype="paintlayer"/>
</root>
"
lineOrder (type lineOrder): increasing y
pixelAspectRatio (type float): 1
screenWindowCenter (type v2f): (0 0)
screenWindowWidth (type float): 1
type (type string): "scanlineimage"
Comment 11 Halla Rempt 2019-07-09 14:08:07 UTC
Okay, I've got it now. This happens whenever there are duplicated layer names in the document, in this case, to layers called "Layer 1".
Comment 12 Halla Rempt 2019-07-09 14:13:25 UTC
Which means ef2f8ea877698dd234fc1f14fd11402bb25a31ec is correct, and fixes the issue.
Comment 13 Bence Mihaly 2019-07-09 15:50:06 UTC
I've just tried to open the fixed file you sent and krita still crashes when I try to open it.
Comment 14 Halla Rempt 2019-07-09 15:58:41 UTC
Eek, I'll give it another try then... The next nightly build has a fix, too. One moment...
Comment 15 Halla Rempt 2019-07-09 16:00:55 UTC
Okay, sent new versions, I hope those work!