Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Vector scalar multiplication crashes at runtime in some cases

Open Hyp-X opened this issue 2 years ago • 1 comments

Context

Odin: dev-2023-06:c1fb8eaf OS: Windows 11 Professional (version: 22H2), build 22622.575 CPU: AMD Ryzen 5 5600X 6-Core Processor RAM: 32689 MiB

Current Behavior

Compiled program crashes with: Unhandled exception at 0x00007FF6E6DFBA0C in OdinHello.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. (Probably an alignment issue)

Steps to Reproduce

package main

import "core:fmt"
import "core:math/linalg"
import "core:math"

scalar: f32
vector: linalg.Vector3f32

main :: proc() 
{
	scalar = 10
	vector = {0, 0.5, 1}

	result := vector * scalar

	fmt.printf("Hello world %v\n", result)
}

With odin run . -use-separate-modules (The crash is not visible unless you use a debugger, but you don't get the "Hello world" output)

The program works as expected when -use-separate-modules is not used. The program also works if I change either scalar or vector to a local variable

Hyp-X avatar Jun 21 '23 11:06 Hyp-X

Hi, I'm experiencing an issue that seems to be similar.

f64Vec2 :: linalg.Vector2f64
mousePos, mouseDelta: f64Vec2 = {0, 0}, {0, 0}

glfwCursorPosCallback :: proc "c" (window: glfw.WindowHandle, xpos, ypos: f64) {
	newPos: f64Vec2 = {xpos, ypos} * mouseSensitivity
	mouseDelta = newPos - mousePos
	mousePos = newPos
}

Error message: Unhandled exception at 0x00007FF7BEF5620B in debug.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF

I've played around a bit with this and the problem seems to be newPos - mousePos. Similarly to the original post the issue goes away if using local variables. For example the following doesn't crash.

newPos: f64Vec2 = {xpos, ypos} * mouseSensitivity
vector1 := mousePos
mouseDelta = newPos - vector1
mousePos = newPos

I can't be sure which change to the language caused this issue but I know that the original code worked 3 weeks ago.

xandaron avatar Aug 04 '24 17:08 xandaron

This may have been related to #2664, but I am unable to replicate it on Linux as of the latest commit, with either module mode.

Feoramund avatar Jun 01 '25 20:06 Feoramund

I can't replicate it on Windows either.

Kelimion avatar Jun 01 '25 20:06 Kelimion