Convert Int.max to CInt cause crash :) #45

Closed
opened 2024-07-26 09:14:10 +02:00 by iDevPro · 2 comments
iDevPro commented 2024-07-26 09:14:10 +02:00 (Migrated from github.com)

Describe the bug

.frame(maxWidth: .max)

cause crash because .max became from Int which Int64 on aarch64 and x86_64 arches :)
but we try to convert it to CInt which Int32 under the hood :)

To Reproduce

  1. Create some view (Text for example)
  2. Append .frame(maxWidth: .max) to it (because there is no .infinity variant from SwiftUI)
  3. Run app
  4. Get crash :)

Expected behavior

Not crash :)

Additional context

I suppose that we need to perform a lossy conversion from Int (which is a synonym for Int64) to CInt (a synonym for Int32) when casting, or not use Int in functions which use CInt at all :)

Workaround:

.frame(maxHeight: Int(CInt.max))
### Describe the bug ```swift .frame(maxWidth: .max) ``` cause crash because .max became from Int which Int64 on aarch64 and x86_64 arches :) but we try to convert it to CInt which Int32 under the hood :) ### To Reproduce 1. Create some view (Text for example) 2. Append `.frame(maxWidth: .max)` to it (because there is no .infinity variant from SwiftUI) 3. Run app 4. Get crash :) ### Expected behavior Not crash :) ### Additional context I suppose that we need to perform a lossy conversion from Int (which is a synonym for Int64) to CInt (a synonym for Int32) when casting, or not use Int in functions which use CInt at all :) Workaround: ```swift .frame(maxHeight: Int(CInt.max)) ```
david-swift commented 2024-07-26 12:44:14 +02:00 (Migrated from github.com)

Thanks for the report! I'll fix this (currently I don't have access to my laptop).

I think you're expecting setting the maximum width to infinity make the view expand horizontally? If this is your goal, use hexpand(_:) instead. frame(maxWidth:) only makes sense when restricting the width.

Thanks for the report! I'll fix this (currently I don't have access to my laptop). I think you're expecting setting the maximum width to infinity make the view expand horizontally? If this is your goal, use [`hexpand(_:)`](https://aparokshaui.github.io/adwaita-swift/documentation/adwaita/view/hexpand(_:)) instead. `frame(maxWidth:)` only makes sense when restricting the width.
david-swift commented 2024-08-25 11:15:17 +02:00 (Migrated from github.com)

I fixed this in 018d21ee65 (1.0.0 branch). It will be fixed in the 1.0.0 release.

I fixed this in https://github.com/AparokshaUI/adwaita-swift/commit/018d21ee65116c7e815be47fda04f5a6d7f75951 (1.0.0 branch). It will be fixed in the 1.0.0 release.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: aparoksha/adwaita-swift#45
No description provided.