Kebbin
03/06/2022, 11:24 AMMartin Nonnenmacher
03/06/2022, 12:28 PMcollectAsState()
with a flow that emits new values very frequently, about 10 times a second. The problem is that the SnapshotStateObserver.applyMaps
property keeps growing and consumes more and more memory over time. This can be reproduced with the code below. A heap dump shows that after 50,000 iterations there is a single instance of androidx.compose.runtime.snapshots.SnapshotStateObserver$ApplyMap[]
that consumes about 100 MB. As it seems to be by design that applyMaps
can only grow, is there a fundamental issue with my code, or is there another approach I could use for frequent updates without eventually running out of memory?
class TestState {
private val scope = CoroutineScope(Dispatchers.Default)
val value = MutableStateFlow(0)
init {
scope.launch {
while (true) {
value.value = value.value + 1
delay(100)
}
}
}
}
@Composable
fun App() {
val state = remember { TestState() }
val value = state.value.collectAsState()
Text("value = ${value.value}")
}
David W
03/07/2022, 12:03 AMrunDistributable
. It runs fine when launched from my application if it's launched via run
; it only fails to load the dlls and crashes when built for dist.
Code here: <https://github.com/davidwhitman/SMOL/blob/dev/App/main/kotlin/smol_app/toolbar/Toolbar.kt#L148> and here <https://github.com/davidwhitman/SMOL/blob/dev/Utilities/main/kotlin/utilities/Utils.kt#L43>
Screenshots and stacktrace: <https://github.com/davidwhitman/SMOL/issues/73>
Things I've tried:
• ProcessBuilder and Runtime exec, same results.
• Copied the dll file to System32, which fixed the problem, I don't know why.
• Many various usages of ProcessBuilder and Runtime exe, same results.
• includeAllModules = true
same results
• Viewed in VisualVM, noted that the java program I'm launching doesn't show up, presumably because it's a subprocess, but that's true even when it works correctly so not sure if relevant.
The other, crashing java program is given the dll path in env variable, but it successfully loads other dlls in the same path (and fails to load them if I rename them).
This is probably too complex/unique for anyone to want to dive deep into, but I'll take any suggestions.
One thing I'd like to try is launching the other java program as a standalone process, not a subprocess, but I haven't found a way to do this at all. cmd /C
doesn't do it.
I should maybe mention that the reason I consider this Compose-related is the difference between it working using run
and not working using runDistributable
. There's something about the Compose build that's changing things.
update: Setting -Djava.library.path
to an absolute path instead of relative seems to fix it. Doesn't make much sense to me, since it loads other .dlls from that folder without issue.
Now I just need to figure out how to get java path variables to allow spaces...
update: Just had to remove the cmd /C
, probably the /C
switch can't handle spaces in paths since it hands it all as a string.
My problem is solved, although I couldn't say why this solution works. It's probably a unique case, but I'll leave this post anyway because you never know.Remo
03/07/2022, 7:45 AMLocalAppWindow
or AppManager
Concret, I’m talking about this function, which should add some default key behaviour when pressing ctrl
+ `q`:
@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun add addDefaultKeyBehaviour(){
val key: Key = if(System.getProperty("os.name") == "Mac OS X") Key.MetaLeft else Key.CtrlLeft
LocalAppWindow.current.keyboard.setShortcut(KeysSet(setOf(key, Key.Q))){
AppManager.focusedWindow?.close()
}
}
As I could not find any migration tutorial, I would appreciate some advice on this 🙂 Thanks in advance!fitken
03/07/2022, 10:52 AMzt
03/07/2022, 11:28 PMDieter Holz
03/08/2022, 10:30 AMKebbin
03/08/2022, 11:01 AMJasin Colegrove
03/08/2022, 11:41 AMzt
03/08/2022, 11:13 PMDragos Rachieru
03/10/2022, 9:38 AMeygraber
03/10/2022, 6:58 PMStefan Oltmann
03/11/2022, 2:29 PMdetectTransformGestures
.
That works on my Android tablet, but does nothing on my MacBooks touchpad.Alex Styl
03/13/2022, 5:39 PMStefan Oltmann
03/14/2022, 3:30 PMandroidx.compose.ui.util.fastAny
and androidx.compose.ui.util.fastForEach
not available?Mario Javier Medina Cocom
03/14/2022, 6:22 PMJasin Colegrove
03/15/2022, 9:57 PMJeanne De ArcRuler
03/16/2022, 6:06 AMLong Tran
03/16/2022, 8:31 AMAlex
03/16/2022, 1:42 PMTim Almdal
03/17/2022, 10:21 PMIconButton/Icon
when the mouse hovers over it. Much like what happens in Winddows, when you move the mouse over the window close button.
I stumble on the MutableInteractSource
but haven't found anything that allows me to et the background. Does anyone have any example I could leverage.
ThanksJasin Colegrove
03/18/2022, 12:18 PMtheapache64
03/19/2022, 8:24 AMjames
03/19/2022, 11:59 AMJohn Aoussou
03/19/2022, 2:09 PM@Composable
fun App() {
var myClass = remember { MyClass() }
MaterialTheme {
Column() {
Text(text="${myClass.myInt.value}")
Button(onClick = myClass::run){ Text(text = "RUN") }
}
}
}
where
class MyClass {
val myInt = mutableStateOf(0)
fun run(){
for (i in 0..10){
myInt.value = i
Thread.sleep(500)
}
}
}
what am I missing?David W
03/19/2022, 7:20 PMrunDistributable
than when run from run
, from a Java CLI jar, or from a Kotlin CLI jar.
Here's the full code of the application (the rest is as generated from the CfD template)
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
Button(onClick = {
ProcessBuilder(
"C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6\\starsector.exe"
)
.directory(File("C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6"))
.start()
}) {
Text("Hello Madness")
}
}
}
The actual issue is hard to describe; starsector.exe
launches a java-based game that runs on its own jre 7/8. The game crashes only when launched from CfD dist because it's unable to resolve some relative file paths that are passed to it from `starsector.exe`as jvm params. Mimicking the functionality of the exe
with a custom java -jar
thing fixes the issue if I use absolute paths for the game files, but this has other side effects (like any windows compat settings applied to the exe
aren't used since I'm working around it.
I don't want to work around the problem; the code works everywhere except as a CfD dist. I can take that ProcessBuilder
code, put it into a pure java or kotlin CLI program, compile a jar, run it, and it'll run the game just fine. Literally it's only when run from runDistributable
(or from the .exe
built from createDistributable
).
Any ideas? What's being done differently by CfD's dist exe?Dragos Rachieru
03/21/2022, 10:27 AMviewModelScope
inside it and use that, so maybe using rememberCoroutineScope()
with it, but I don't know how to do it properly.Remo
03/21/2022, 3:22 PMonClick
). Although, getting the compiler error @Composable invocations can only happen from the context of a @Composable function
since onClick
does not seem to accept a Composable
function as argument. What would I need to change in my code to get this work?
Code:
@Composable
private fun showDialogButton(){
Button(onClick = {openDialog()}){
Text("Hello Button")
}
}
@Composable
private fun openDialog(){
Dialog(onCloseRequest = {}, title = "Dialog"){
Button(onClick = {}) {
Text("Close Dialog")
}
}
}
Balaviknesh Sekar
03/21/2022, 8:30 PMmcpiroman
03/22/2022, 1:24 PMmcpiroman
03/22/2022, 1:24 PMjw
03/22/2022, 1:30 PMmcpiroman
03/22/2022, 1:43 PMspierce7
03/22/2022, 2:27 PMmcpiroman
03/22/2022, 2:45 PM