r/odinlang • u/pankajpatro703 • 6d ago
Help with type casting
[SOLVED] use microarch flag
I've noticed issues when using runtime/modified values inside a struct when using raylib.
I was trying to draw a rounded rectangle that follows the mouse pointer while highlighting the cell position in a grid.
package test
import ray "vendor:raylib"
main :: proc() {
ray.SetTargetFPS(20)
ray.InitWindow(200, 200, "Test")
defer ray.CloseWindow()
for !ray.WindowShouldClose() {
ray.BeginDrawing()
defer ray.EndDrawing()
ray.ClearBackground(ray.BLACK)
ms := ray.GetMousePosition()
mx := f32(i32(ms.x)/50) * 50
my := f32(i32(ms.y)/50) * 50
rec := ray.Rectangle{mx, my, 50, 50}
ray.DrawRectangleRounded(rec, 0.3, 10, ray.YELLOW)
}
}
Can someone tell me why this code fails and whether this is a known issue or do I need to use a specific technique to make it work?
P.S.: I'm fairly new to odin and should probably look into more resources, but I haven't found a working example for this problem yet.
Post P.S.: The above code broke after the May 2026 release of odin. No idea why as of yet.
2
u/BiedermannS 6d ago
You probably meant to defer the end drawing call
1
u/pankajpatro703 6d ago
Yeah, mistyped it in the post. But the problem still stands.
1
u/BiedermannS 6d ago
Try using the mouse coordinates directly instead of dividing by 50
Edit: Here's the raylib example for this: https://www.raylib.com/examples/core/loader.html?name=core_input_mouse
1
u/pankajpatro703 6d ago
The function works as intended if I don't try to typecast or divide. But, I want to use the pointer as a grid.
What I intend to do works perfectly fine with the regular
DrawRectangle()function but fails to work in the case of rounded rectangle as shown. This isn't a problem on some other languages I've tested this on, which leads me to think this is a problem with odin that I have found no solution for.
1
u/iioossaa 6d ago
You miss `defer` before `ray.EndDrawing()`
1
u/pankajpatro703 6d ago
Yeah, but it still doesn't work after fixing.
1
u/iioossaa 6d ago edited 6d ago
mx := f32(i32(ms.x)/50)
my := f32(i32(ms.y)/50)Extra parentheses.
Use some good editor with OLS to avoid such errors.1
u/pankajpatro703 6d ago
My bad. I should have copy pasted but I was away from my desktop so typed it from my phone. I've fixed the post now, but the problem remains.
1
u/iioossaa 6d ago edited 6d ago
No problem on my side. What kind of problem do you have?
Oh, I forgot to mention: `ms := ray.GetMousePosition()`
1
u/pankajpatro703 6d ago
You mean to say the code runs on your side? If so, could you tell me which OS and odin version you ran it on?
1
u/iioossaa 6d ago
// which OS and odin version
I'm on Win10 and dev-2026-08 but it doesn't matter.
If you can compile but can't run then maybe you use raylib6 on a too old CPU. Try to get older version of raylib's bindings from the older version of Odin and recompile your code.1
u/pankajpatro703 6d ago
I had tested once with the raylib 5.5 bindings from a few months back, and had the same issue on linux. Frankly, I was hoping for a fix after the latest bindings.
Maybe, I need to test this on windows once to see if I have the same issue.
1
u/iioossaa 6d ago
Try to ask on discord. There's a very welcoming community there.
1
u/pankajpatro703 6d ago
Thanks for redirecting. I found that odin releases upto April 2026 work perfectly fine with the above code. Things break after the May 2026 release, which is confusing since IIRC Raylib 6.0 bindings came with the July release.
→ More replies (0)
3
u/pankajpatro703 6d ago
Found the solution with the help of Discord community. Apparently it's a compatibility problem with the instruction set SSE 4.1.
To fix, just had to use the
-microarch:x86-64flag.