Skip to content

Example program throws Unhandled Exception 0xC0000374 on Windows #41

Open
@TimmieTudor

Description

@TimmieTudor

Describe the bug

When I try compiling and running the code at the beginning of the README.md file, it throws an Unhandled Exception that means (A heap has been corrupted.)

Expected Behavior

I expected the program to compile, run and return the same thing as in the example.

Current Behavior

The code throws the following error when I run "v run src/main.v":
Unhandled Exception 0xC0000374
print_backtrace_skipping_top_frames is not implemented

Reproduction Steps

The steps can be reproduced on Windows with this code:

module main

import vtl

fn main() {
	t := vtl.from_1d([1,2,3,4])!
	println(t)
}

Possible Solution

The vtl.from_1d method calls the vtl.from_array method. There is a bug in the vtl.from_array method that is causing the heap to be corrupted. One possible solution would be to investigate and see what part of the vtl.from_array method is causing the exception on Windows

Additional Information/Context

I tried looking into the source of the vtl.from_array method, and this is what I found:

// from_varray takes a one dimensional array of T values
// and coerces it into an arbitrary shaped Tensor if possible.
// Panics if the shape provided does not hold the provided array
pub fn from_array[T](arr []T, shape []int, params TensorData) !&Tensor[T] {
	size := size_from_shape(shape)
	if size != arr.len {
		return error('Bad shape for array, shape [${arr.len}] cannot fit into shape ${shape}')
	}
	data_storage := storage.from_array[T](arr)
	if shape.len == 0 {
		return &Tensor[T]{
			memory: params.memory
			strides: [1]
			shape: []
			size: size
			data: data_storage
		}
	}
	strides := strides_from_shape(shape, params.memory)
	return &Tensor[T]{
		shape: shape
		strides: strides
		memory: params.memory
		size: size
		data: data_storage
	}
}

I think one of the returns is problematic, or maybe the strides are calculated incorrectly, but all I know is the error is related to the heap being corrupted, so it's probably one of the Tensor references being returned.

V version

V 0.4.0 d53d959

Version used

0.2.0

Environment details (OS name and version, etc.)

V full version: V 0.4.0 3a91a5e.d53d959
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 12 cpus, 64bit, little endian,

getwd: C:\Users\tudor.vmodules\vtl\src
vexe: C:\Users\tudor\Documents\v_windows\v\v.exe
vexe mtime: 2023-07-27 16:15:47

vroot: OK, value: C:\Users\tudor\Documents\v_windows\v
VMODULES: OK, value: C:\Users\tudor.vmodules
VTMP: OK, value: C:\Users\tudor\AppData\Local\Temp\v_0

Git version: git version 2.41.0.windows.3
Git vroot status: weekly.2023.30-14-gd53d9599
.git/config present: true

CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
cmd: cc --version
thirdparty/tcc: N/A

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions