Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Width (0) and height (0) cannot be <= 0" error or font resource loading error or empty screenshot issue #1288

Open
alashow opened this issue Feb 9, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@alashow
Copy link

alashow commented Feb 9, 2024

Description
Note: re-opening #1054 because it was closed and now it's failing with upgrading composeBom to latest stable vs alpha version of constraintLayout.

When upgrading from composeBom 2023.10.01 to 2024.02.00, screenshot tests start failing with empty screens or these errors:

Variant 1:
ava.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
	at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
	at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:333)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:468)
	at app.cash.paparazzi.Paparazzi$takeSnapshots$1$3.invoke(Paparazzi.kt:329)
	at app.cash.paparazzi.Paparazzi$takeSnapshots$1$3.invoke(Paparazzi.kt:328)
	at app.cash.paparazzi.Paparazzi.withTime(Paparazzi.kt:376)
	at app.cash.paparazzi.Paparazzi.takeSnapshots(Paparazzi.kt:328)
	at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:214)
	at app.cash.paparazzi.Paparazzi.snapshot$default(Paparazzi.kt:213)
	at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:209)

Variant 2
java.lang.IllegalStateException: Could not load font
	at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:207)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve(FontFamilyResolver.kt:92)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve-DPcqOEQ(FontFamilyResolver.kt:79)
	at androidx.compose.foundation.text.HeightInLinesModifierKt$heightInLines$2.invoke(HeightInLinesModifier.kt:73)
	at androidx.compose.foundation.text.HeightInLinesModifierKt$heightInLines$2.invoke(HeightInLinesModifier.kt:52)
	at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:270)
	at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:265)
	at androidx.compose.ui.Modifier$Element.foldIn(Modifier.kt:136)
.....
android.content.res.Resources$NotFoundException: Font resource ID #0x7f09000f could not be retrieved.

Steps to Reproduce
Not able to cleanly reproduce this yet. Before it was happening with constraintLayout alpha versions, now not sure what library is causing this exactly.

Project sample fails with different error when adding all composeBom library dependencies (PlatformTextInputPluginRegistryImpl classnotfound error)

Additional information:

  • Paparazzi Version: 1.3.1, 1.3.2, 1.3.3-SNAPSHOT
  • OS: osx sonoma
  • Compile SDK: 34
  • Gradle Version: 8.2.1
  • Android Gradle Plugin Version: 8.2.2

Screenshots
See screenshots in #1054

@alashow alashow added the bug Something isn't working label Feb 9, 2024
@JeremiahStephenson
Copy link

JeremiahStephenson commented Feb 9, 2024

I started getting this after specifically updating Material3 to 1.2.0. Any previews that display text with custom font will fail and the snapshot comes out blank.

@jrodbx
Copy link
Collaborator

jrodbx commented Feb 12, 2024

@alashow thanks for reopening. without a repro, this remains a challenge to solve. Also, how certain are you that the two variants are related, i.e., the same bug?

@JeremiahStephenson re: "any previews that display text will fail" so this might be an layoutlib issue?

One thing I just noticed is that compileSdk = 34 is specified, but Paparazzi currently only supports up to API 33, due to its dependency on layoutlib being pinned (at the moment) to Giraffe (link)

Have you updated the environment accordingly, i.e.,

Paparazzi(
  environment = detectEnvironment().run {
    copy(compileSdkVersion = 33, platformDir = platformDir.replace("34", "33"))
  },
)

?

@JeremiahStephenson
Copy link

@jrodbx No, that doesn't fix my issue. The issue for me only came up after updating material3 to the latest stable version 1.2.0.

@alashow
Copy link
Author

alashow commented Feb 13, 2024

Also, how certain are you that the two variants are related, i.e., the same bug?

Both errors show up after updating composeBom to latest, so that's the only reason I think they're related.

Have you updated the environment accordingly, i.e.,

Yes, I did apply the fix from #1025, compileSdk = 34 doesn't work otherwise.

@alashow
Copy link
Author

alashow commented Feb 13, 2024

Indeed, only tests using Text component fail. So I tested more with it and it seems like it's related to fontFamily..

After debugging I found out that it only fails when using custom fontFamily. I changed our default fontFamily from custom one to FontFamily.Default, and re-recorded tests - all tests got recorded / didn't fail with above errors.

Then I tried specifying loadingStrategy when initializing our custom fontFamily, i.e:

FontFamily(
    fonts = listOf(
        Font(
            resId = R.font.customFont,
            weight = FontWeight.Thin,
            style = FontStyle.Normal,
            loadingStrategy= FontLoadingStrategy.Async,
        )
        ...,
)

and again screenshot test didn't fail when running. Changing loadingStrategy from default FontLoadingStrategy.Blocking to FontLoadingStrategy.Async or even FontLoadingStrategy.OptionalLocal makes the tests work again. The actual font specified isn't rendered of course, I assume because they're rendered a bit after / they're still being loaded in background / async(?)

So if this is a layoutlib issue, does it mean the same components using Text with custom font shouldn't be rendered in preview mode when the same layoutlib version of paparazzi is used by Android Studio?

@renovater8
Copy link

Description Note: re-opening #1054 because it was closed and now it's failing with upgrading composeBom to latest stable vs alpha version of constraintLayout.

When upgrading from composeBom 2023.10.01 to 2024.02.00, screenshot tests start failing with empty screens or these errors:

Variant 1:
ava.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
	at java.desktop/java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
	at java.desktop/java.awt.image.BufferedImage.<init>(BufferedImage.java:333)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:468)
	at app.cash.paparazzi.Paparazzi$takeSnapshots$1$3.invoke(Paparazzi.kt:329)
	at app.cash.paparazzi.Paparazzi$takeSnapshots$1$3.invoke(Paparazzi.kt:328)
	at app.cash.paparazzi.Paparazzi.withTime(Paparazzi.kt:376)
	at app.cash.paparazzi.Paparazzi.takeSnapshots(Paparazzi.kt:328)
	at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:214)
	at app.cash.paparazzi.Paparazzi.snapshot$default(Paparazzi.kt:213)
	at app.cash.paparazzi.Paparazzi.snapshot(Paparazzi.kt:209)

Variant 2
java.lang.IllegalStateException: Could not load font
	at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:207)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve(FontFamilyResolver.kt:92)
	at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve-DPcqOEQ(FontFamilyResolver.kt:79)
	at androidx.compose.foundation.text.HeightInLinesModifierKt$heightInLines$2.invoke(HeightInLinesModifier.kt:73)
	at androidx.compose.foundation.text.HeightInLinesModifierKt$heightInLines$2.invoke(HeightInLinesModifier.kt:52)
	at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:270)
	at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:265)
	at androidx.compose.ui.Modifier$Element.foldIn(Modifier.kt:136)
.....
android.content.res.Resources$NotFoundException: Font resource ID #0x7f09000f could not be retrieved.

Steps to Reproduce Not able to cleanly reproduce this yet. Before it was happening with constraintLayout alpha versions, now not sure what library is causing this exactly.

Project sample fails with different error when adding all composeBom library dependencies (PlatformTextInputPluginRegistryImpl classnotfound error)

Additional information:

  • Paparazzi Version: 1.3.1, 1.3.2, 1.3.3-SNAPSHOT
  • OS: osx sonoma
  • Compile SDK: 34
  • Gradle Version: 8.2.1
  • Android Gradle Plugin Version: 8.2.2

Screenshots See screenshots in #1054

I think it also was reading sent under note and day and date was only saying today or yesterday also but I did notice if you reset your camera in settings for just the camera it works like new only once in settings u have to adjust it then like right away.

@renovater8
Copy link

I think just a simple reset would change it all unless u have a cheap phone

@alashow
Copy link
Author

alashow commented Feb 20, 2024

@renovater8 what are you going on about?

rafsanjani added a commit to rafsanjani/superdiary that referenced this issue Mar 1, 2024
rafsanjani added a commit to rafsanjani/superdiary that referenced this issue Mar 1, 2024
rafsanjani added a commit to rafsanjani/superdiary that referenced this issue Mar 1, 2024
@rafsanjani
Copy link

rafsanjani commented Mar 3, 2024

@alashow loadingStrategy is not available on Compose Multiplatform.

@alashow
Copy link
Author

alashow commented Apr 30, 2024

@jrodbx any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants