External DLL calls with 5 arguments don't work on Windows x86-64 #21

Closed
opened 2025-08-22 11:01:31 +00:00 by Furkan · 10 comments

Example

raylib.BeginDrawing()													// 0 args works
raylib.ClearBackground(Color{r: 0, g: 0, b: 0, a: 255}) 			    // 1 args works
raylib.DrawFPS(10, 10)                                                  // 2 args works
raylib.DrawPixel(100, 100, Color{r: 255, g: 0, b: 0, a: 255})           // 3 args works
raylib.DrawLine(100, 100, 200, 200, Color{r: 0, g: 255, b: 0, a: 255})  // 4 args doesn't work crashes at this line

// Definations
BeginDrawing()
ClearBackground(color Color)
DrawFPS(x int, y int);
DrawPixel(x int, y int, color Color);
DrawLine(x1 int, y1 int, x2 int, y2 int, color Color);

Error:
exit status 0xc0000005 (Access Violation)

Example ``` raylib.BeginDrawing() // 0 args works raylib.ClearBackground(Color{r: 0, g: 0, b: 0, a: 255}) // 1 args works raylib.DrawFPS(10, 10) // 2 args works raylib.DrawPixel(100, 100, Color{r: 255, g: 0, b: 0, a: 255}) // 3 args works raylib.DrawLine(100, 100, 200, 200, Color{r: 0, g: 255, b: 0, a: 255}) // 4 args doesn't work crashes at this line // Definations BeginDrawing() ClearBackground(color Color) DrawFPS(x int, y int); DrawPixel(x int, y int, color Color); DrawLine(x1 int, y1 int, x2 int, y2 int, color Color); ``` Error: exit status 0xc0000005 (Access Violation)
ed self-assigned this 2025-08-22 11:50:06 +00:00
Owner

Thanks!
Fixed in cli/q@4f423c5a95.

I was able to draw a green line from 10, 10 to 100, 100 but for some reason I still have some troubles with the original coordinates in your report.

Edit:

I think the optimizer might be doing something weird here. It only works if I use starting coordinates with numbers that already appeared in the code before. That's definitely pointing towards an internal optimization bug.

Thanks! Fixed in https://git.urbach.dev/cli/q/commit/4f423c5a952578f61352b4a0225d5fc5c62d554b. I was able to draw a green line from `10, 10` to `100, 100` but for some reason I still have some troubles with the original coordinates in your report. *Edit:* I think the optimizer might be doing something weird here. It only works if I use starting coordinates with numbers that already appeared in the code before. That's definitely pointing towards an internal optimization bug.
Author

Original coordinates works for me (Also tested some more coords and it works)

Could it be a wine issue?

Edit I tried some more coords

if any of the args is 0 it says: panic: shift destination cannot be R1
I tried line from 10, 10 to 100, 100 and it said: panic: no free registers

Original coordinates works for me (Also tested some more coords and it works) Could it be a wine issue? Edit I tried some more coords if any of the args is 0 it says: panic: shift destination cannot be R1 I tried line from 10, 10 to 100, 100 and it said: panic: no free registers
Owner

Original coordinates works for me (Also tested some more coords and it works)

Could you please post the working code? Then I can compare to see what's going on.

> Original coordinates works for me (Also tested some more coords and it works) Could you please post the working code? Then I can compare to see what's going on.
Author
main() {
	raylib.InitWindow(1280, 720, "raylib example\0".ptr)
	monitor := raylib.GetCurrentMonitor()
	fps := raylib.GetMonitorRefreshRate(monitor)
	raylib.SetTargetFPS(fps)

	loop {
		if raylib.WindowShouldClose() {
			return
		}

		raylib.BeginDrawing()													
		raylib.ClearBackground(Color{r: 0, g: 0, b: 0, a: 255}) 			 
 		raylib.DrawFPS(10, 10)                                               
		raylib.DrawPixel(100, 100, Color{r: 255, g: 0, b: 0, a: 255})        
		raylib.DrawLine(10, 10, 200, 200, Color{r: 0, g: 255, b: 0, a: 255})  
		raylib.EndDrawing()
	}
}

Color {
	r byte
	g byte
	b byte
	a byte
}

extern {
	raylib {
		BeginDrawing()
		ClearBackground(color Color)
		EndDrawing()
		GetCurrentMonitor() -> int
		GetMonitorRefreshRate(monitor int) -> int
		InitWindow(width int, height int, title *byte)
		DrawFPS(x int, y int);
		DrawPixel(x int, y int, color Color);
		DrawLine(x1 int, y1 int, x2 int, y2 int, color Color);
		SetTargetFPS(fps int)
		WindowShouldClose() -> bool
	}
}

I use dll from raylib-5.5_win64_msvc16.zip on github releases

``` main() { raylib.InitWindow(1280, 720, "raylib example\0".ptr) monitor := raylib.GetCurrentMonitor() fps := raylib.GetMonitorRefreshRate(monitor) raylib.SetTargetFPS(fps) loop { if raylib.WindowShouldClose() { return } raylib.BeginDrawing() raylib.ClearBackground(Color{r: 0, g: 0, b: 0, a: 255}) raylib.DrawFPS(10, 10) raylib.DrawPixel(100, 100, Color{r: 255, g: 0, b: 0, a: 255}) raylib.DrawLine(10, 10, 200, 200, Color{r: 0, g: 255, b: 0, a: 255}) raylib.EndDrawing() } } Color { r byte g byte b byte a byte } extern { raylib { BeginDrawing() ClearBackground(color Color) EndDrawing() GetCurrentMonitor() -> int GetMonitorRefreshRate(monitor int) -> int InitWindow(width int, height int, title *byte) DrawFPS(x int, y int); DrawPixel(x int, y int, color Color); DrawLine(x1 int, y1 int, x2 int, y2 int, color Color); SetTargetFPS(fps int) WindowShouldClose() -> bool } } ``` I use dll from raylib-5.5_win64_msvc16.zip on github releases
ed changed title from External DLL calls with more than 3 arguments doesn't work [Windows x86-64] to External DLL calls with 5 arguments don't work on Windows x86-64 2025-08-22 15:46:56 +00:00
Owner

Edit I tried some more coords

if any of the args is 0 it says: panic: shift destination cannot be R1 I tried line from 10, 10 to 100, 100 and it said: panic: no free registers

Fixed in cli/q@26099e691c.

I reduced the pressure on registers significantly.
It seems to work with any coordinates now.

> Edit I tried some more coords > > if any of the args is 0 it says: panic: shift destination cannot be R1 I tried line from 10, 10 to 100, 100 and it said: panic: no free registers Fixed in https://git.urbach.dev/cli/q/commit/26099e691c8adcb6b14c6d2c2f8a4fde6e9e950a. I reduced the pressure on registers significantly. It seems to work with any coordinates now.
ed added spent time 2025-08-22 17:16:18 +00:00
4 hours
Owner

Fun fact, I get 8k FPS in Windows and 16k FPS in Linux/WINE 😄

The commit also improved the performance.
There are still a few optimizations left that we can do for DLL calls on Windows, so it can be even higher.

Feel free to close the issue if it works for you!

Fun fact, I get 8k FPS in Windows and 16k FPS in Linux/WINE 😄 The commit also improved the performance. There are still a few optimizations left that we can do for DLL calls on Windows, so it can be even higher. Feel free to close the issue if it works for you!
Author

Getting more fps on linux is really funny lol I wish I could switch to linux one day (my manufacturer has a terrible linux support literally unusable)

I encountered some more issues but Im not sure if they are related to dll calls or structs

also I feel like Im spamming issues Im sure you have other stuff to do and I don't want to rush you


    Player {
    	x int
    	y int
    	w int
    	h int
    }

	player := Player{
		x : 640
		y : 360
		w : 32
		h : 32
	}

	raylib.DrawRectangle(player.x, player.y, player.w, player.h, GREEN)

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x38 pc=0x7ff7a50ce864]

goroutine 34 [running]:
git.urbach.dev/cli/q/src/core.(*Function).evaluateStruct(0xc000102180, 0xc000194990)
C:/Furkan/Dev/q/src/core/evaluateStruct.go:35 +0x2c4
git.urbach.dev/cli/q/src/core.(*Function).evaluate(0xc0001c64b0?, 0xc00018e180?)
C:/Furkan/Dev/q/src/core/evaluate.go:26 +0x71
........
........

Getting more fps on linux is really funny lol I wish I could switch to linux one day (my manufacturer has a terrible linux support literally unusable) I encountered some more issues but Im not sure if they are related to dll calls or structs also I feel like Im spamming issues Im sure you have other stuff to do and I don't want to rush you --- ``` Player { x int y int w int h int } player := Player{ x : 640 y : 360 w : 32 h : 32 } raylib.DrawRectangle(player.x, player.y, player.w, player.h, GREEN) ``` panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x38 pc=0x7ff7a50ce864] goroutine 34 [running]: git.urbach.dev/cli/q/src/core.(*Function).evaluateStruct(0xc000102180, 0xc000194990) C:/Furkan/Dev/q/src/core/evaluateStruct.go:35 +0x2c4 git.urbach.dev/cli/q/src/core.(*Function).evaluate(0xc0001c64b0?, 0xc00018e180?) C:/Furkan/Dev/q/src/core/evaluate.go:26 +0x71 ........ ........
Owner

I encountered some more issues but Im not sure if they are related to dll calls or structs

I took a look at it and it's related to struct fields missing commas, so that one would be a different topic.

	player := Player{
		x: 640,
		y: 360,
		w: 32,
		h: 32
	}

I will add a proper error message to the compiler.

also I feel like Im spamming issues Im sure you have other stuff to do and I don't want to rush you

Don't worry! Your bug reports are very useful!

> I encountered some more issues but Im not sure if they are related to dll calls or structs I took a look at it and it's related to struct fields missing commas, so that one would be a different topic. ``` player := Player{ x: 640, y: 360, w: 32, h: 32 } ``` I will add a proper error message to the compiler. > also I feel like Im spamming issues Im sure you have other stuff to do and I don't want to rush you Don't worry! Your bug reports are **very useful**!
Owner

Error messages for struct evaluation are now available in cli/q@4af3c3283a.

I prefer to have one issue for each topic, so if you find 3 new problems then please feel free to open 3 different issues!
It's not spamming, it actually helps me focus on one topic at a time.

Error messages for struct evaluation are now available in https://git.urbach.dev/cli/q/commit/4af3c3283a62ad3580587850af4a625936a0a666. I prefer to have one issue for each topic, so if you find 3 new problems then please feel free to open 3 different issues! It's not spamming, it actually helps me focus on one topic at a time.
Author

Thanks, I'm closing the issue now

Thanks, I'm closing the issue now
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Total time spent: 4 hours
ed
4 hours
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cli/q#21
No description provided.