Bug 420033

Summary: New layer number always starts from 1 when editing present PSD files
Product: [Applications] krita Reporter: Yu-Hsuan Lai <raincolee>
Component: Layer StackAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: normal CC: dimula73, tusooa
Priority: NOR    
Version: 4.2.9   
Target Milestone: ---   
Platform: macOS (DMG)   
OS: macOS   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: When there are more existing layers

Description Yu-Hsuan Lai 2020-04-13 14:08:44 UTC
Created attachment 127508 [details]
When there are more existing layers

SUMMARY
When editing a PSD file, even with a layer named "Layer 1" presents, the newly added layer is still named "Layer 1" instead of "Layer 2.

STEPS TO REPRODUCE
1. Create a PSD file in Photoshop with a layer named "Layer 1"
2. Open said PSD file in Krita
3. Create a new layer

OBSERVED RESULT
The new layer is named "Layer 1" too.


EXPECTED RESULT
The new layer should be named "Layer 2".

SOFTWARE/OS VERSIONS
SUMMARY
I still got random crashes on my Mac, even with canvas acceleration disabled. It happens about once a day.

STEPS TO REPRODUCE
Can't figure out the consistent reproducing steps. It seems pretty random.


OBSERVED RESULT
Crash

EXPECTED RESULT
Not crash

SOFTWARE/OS VERSIONS
macOS: 10.14.6
Krita: 4.9.2

ADDITIONAL INFORMATION
See attachment
Comment 1 tusooa 2020-04-13 21:31:08 UTC
Hi Yu-Hsuan,

Thank you for your report.

I confirm this on 4.2.7.1.

I also found out that if you created a kra file with a "Background Layer," when you re-open the file, the new layer you created will be "Layer (number of current layers + 1)."

This holds even if the layer name is a duplicate.

I guess the info about KisNameServer does not get saved into either file formats, but the two formats seem to use different methods to initialize the name server when opening the file. I think this is a bug.
Comment 2 tusooa 2020-04-13 21:36:45 UTC
(In reply to Yu-Hsuan Lai from comment #0)
> SOFTWARE/OS VERSIONS
> SUMMARY
> I still got random crashes on my Mac, even with canvas acceleration
> disabled. It happens about once a day.
> 
> STEPS TO REPRODUCE
> Can't figure out the consistent reproducing steps. It seems pretty random.
> 
> 
> OBSERVED RESULT
> Crash
> 
> EXPECTED RESULT
> Not crash
> 

Also, for the crash thing, I suggest you making a separate bug report for it. It would be nice if you can also send a crash log. The way to generate one can be seen at https://docs.krita.org/en/reference_manual/sharing_krita_logs.html?highlight=crash#getting-backtrace .
Comment 3 Yu-Hsuan Lai 2020-04-14 08:17:20 UTC
(In reply to tusooa from comment #2)
> (In reply to Yu-Hsuan Lai from comment #0)
> > SOFTWARE/OS VERSIONS
> > SUMMARY
> > I still got random crashes on my Mac, even with canvas acceleration
> > disabled. It happens about once a day.
> > 
> > STEPS TO REPRODUCE
> > Can't figure out the consistent reproducing steps. It seems pretty random.
> > 
> > 
> > OBSERVED RESULT
> > Crash
> > 
> > EXPECTED RESULT
> > Not crash
> > 
> 
> Also, for the crash thing, I suggest you making a separate bug report for
> it. It would be nice if you can also send a crash log. The way to generate
> one can be seen at
> https://docs.krita.org/en/reference_manual/sharing_krita_logs.
> html?highlight=crash#getting-backtrace .

Oh I made a separate report: https://bugs.kde.org/show_bug.cgi?id=420032

I just copied paste from it and forget to delete the extra characters. Sorry for the confusion.
Comment 4 Dmitry Kazakov 2020-07-30 14:05:24 UTC
Git commit 4a50d2f5931b5a414c9e48b23000e3d9212cf145 by Dmitry Kazakov.
Committed on 30/07/2020 at 14:05.
Pushed by dkazakov into branch 'krita/4.3'.

Fix layer index generation algorithm

Now the index is assigned to a layer dynamically. We just iterate over
all the existing layers, find ones with index in the end of the name,
choose the maximum one and create a new layer with index (maxIndex + 1).

M  +18   -14   libs/image/kis_image.cc
M  +0    -5    libs/image/kis_image.h
M  +0    -1    plugins/impex/libkra/kis_kra_loader.cpp

https://invent.kde.org/graphics/krita/commit/4a50d2f5931b5a414c9e48b23000e3d9212cf145
Comment 5 Dmitry Kazakov 2020-07-30 16:08:56 UTC
Git commit b9df04d61453401db48152ca84c6936990c17552 by Dmitry Kazakov.
Committed on 30/07/2020 at 14:08.
Pushed by dkazakov into branch 'master'.

Fix layer index generation algorithm

Now the index is assigned to a layer dynamically. We just iterate over
all the existing layers, find ones with index in the end of the name,
choose the maximum one and create a new layer with index (maxIndex + 1).

# Conflicts:
#	libs/image/kis_image.cc

M  +18   -14   libs/image/kis_image.cc
M  +0    -5    libs/image/kis_image.h
M  +0    -1    plugins/impex/libkra/kis_kra_loader.cpp

https://invent.kde.org/graphics/krita/commit/b9df04d61453401db48152ca84c6936990c17552