https://kotlinlang.org logo
Title
w

willyrs

07/03/2020, 6:02 PM
Hi all! I’ve written a reducer function like this:
val splashReducer: Reducer<SplashState> =  { state, action -> return state }
and when I call it on iOS I have a EXC_BAD_ACCESS (code=1, address=0x0) error If I write the function like this:
fun splashReducer(state: SplashState, action: Any) : SplashState { return state }
it works! Do you think it’s a problem with reduxkotlin or with kotlin-native? P.S. On kotlin-android it works with both
p

Patrick Jackson

07/03/2020, 6:30 PM
Does this happen when the store is created? I Perhaps a threading issue. The val is initiated at some point (not sure if this is app start up, or first time code from this file is accessed). f so is the store a global val? or part of a class? which thread is it initiated on? If this is open source feel free to drop a link
w

willyrs

07/03/2020, 6:34 PM
I also thought about a threading issue, but I can’t solve it even with @SharedImmutable or @ThreadLocal Yes, this is a public repository, but still very very work in progress 🙂 https://github.com/EmmanueleVilla/apod-kampkit In the last commit it works because I’ve changed everything to “fun”. The commit with the crash should be 4db0a73 but I can’t check for sure right now!
and yes, it happens when the store is created! everything is a global val, I’m trying to keep it all functional so there are no wrapping classes. I’ve tried to put everything in a companion object with @SharedImmutable but I had lots of issues of solving all the IncorrectDereferenceException that came with it
p

Patrick Jackson

07/03/2020, 6:45 PM
Gotcha. I remember having this issue before. It's been awhile since then and not sure what my conclusions where. It would be great to document any findings. Couple of ideas: 1) try to use
by lazy
with the reducer and/or store. 2) use a container object for the store and/or reducers 3) just use the fun
w

willyrs

07/03/2020, 6:49 PM
thanks for the tips! I’ll try both 1 and 2 and see what happens. I’m happy to use 3 and never think about it anymore, I just wanna do some tests to know what’s happening under the hood
p

Patrick Jackson

07/03/2020, 6:58 PM
Agreed. Please share any findings. I might add a page in the documentation - or you can 🙂
👍 1
w

willyrs

07/06/2020, 4:29 PM
I still had no change to try them, I’m doing this on my spare time 🙂 I’ve built a multiplatform project with the core business logic based on reduxkotlin with jvm server and react-android-ios client
I think I tried to use companion objects before writing here, I didnt have this particular error, but I got a lot of IncorrectDereferenceException everywhere
maybe it’ll work by putting everything inside a companion object, but i mean.. why 😄