dimdin
June 30, 2024, 4:22pm
2
Replace:
if (failed(draw7.IDirectDraw7_SetDisplayMode( //
WIDTH, HEIGHT, 8, 0, 0))) win32Panic();
With:
const hr = draw7.IDirectDraw7_SetDisplayMode( //
WIDTH, HEIGHT, 8, 0, 0);
if (failed(hr)) {
std.log.err("hr={x}\n", .{hr});
win32Panic();
}
Possible hr
values are specified in IDirectDraw7::SetDisplayMode
The value must be 0x8876####
where ####
is an error code defined in ddraw.h
1 Like
I changed the code, and get a hr error code: -7fffbfff.
the code means DDERR_ALREADYINITIALIZED? What is initialized?
PS C:\workspace\demo> zig build run
info: wWinMain
info: WM_CREATE
info: gameInit
error: hr=-7fffbfff
error: win32 painc code 5
thread 23900 panic: ERROR_ACCESS_DENIED
C:\workspace\demo\src\main.zig:120:12: 0x3b1c87 in win32Panic (demo.exe.obj)
@panic (@tagName (err));
^
C:\workspace\demo\src\main.zig:99:19: 0x3b1de1 in gameInit (demo.exe.obj)
win32Panic();
^
C:\workspace\demo\src\main.zig:64:13: 0x3b13d0 in wWinMain (demo.exe.obj)
gameInit();
^
C:\software\exe\zig\lib\std\start.zig:577:25: 0x3b10f2 in call_wWinMain (demo.exe.obj)
return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow);
^
C:\software\exe\zig\lib\std\start.zig:374:53: 0x3b1013 in wWinMainCRTStartup (demo.exe.obj)
const result: std.os.windows.INT = call_wWinMain();
^
???:?:?: 0x7ffde176257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffde208aa57 in ??? (ntdll.dll)
-7fffbfff = 80004001 = E_NOTIMPL = DDERR_UNSUPPORTED = Action not supported.
Thanks for explaining the error code. Is this a win32 error code or a zigwin32? Hmm…it should be a win32 error.
I don’t get such errors when using cpp. source code: demo/main.cpp at win32-panic · jiangbo/demo · GitHub .
I am very confused now, not sure whether it is a problem with the zig code or my computer environment.
The cpp code ignores any errors returned from SetDisplayMode
and Game_Init
.
The result of using the FAILED macro is also correct. Because I want to see the return value of SetDisplayMode, I store it in r. From the debug image above, you can see that the value of r is S_OK, which means no error.
The only difference I 've seen in the code is the use of CW_USEDEFAULT
instead of 0
in CreateWindowEx
.
I tried running examples of zig and cpp on my computer separately, and they both returned the 80004001
error.
Should use 32-bit mode instead of 64-bit mode
If this means you are targeting x86-windows
and not x86_64-windows
, then be aware that Zig >= 0.13.0 currently has known miscompilations for 32-bit Windows, so that might be causing your original problem:
opened 11:52AM - 23 May 24 UTC
bug
os-windows
arch-x86
backend-llvm
regression
### Zig Version
0.13.0-dev.249+ed75f6256
### Steps to Reproduce and Observ… ed Behavior
When running the standard library tests with `-target x86-windows` I hit:
```
> zig test lib\std\std.zig --zig-lib-dir lib -target x86-windows
Test [2/2716] debug.decltest.machoSearchSymbols... expected debug.MachoSymbol@2b13464, found debug.MachoSymbol@2b13468
Test [2/2716] debug.decltest.machoSearchSymbols... FAIL (TestExpectedEqual)
Segmentation fault at address 0x0
Segmentation fault at address 0x0
Segmentation fault at address 0x0
Segmentation fault at address 0x0
Panicked during a panic. Aborting.
error: the following test command failed with exit code 3:
C:\Users\Ryan\Programming\Zig\zig\zig-cache\o\6b0eda73b9d23fabe1b7288a523661d4\test.exe
```
After updating `resinator` to latest Zig I hit many similar problems when targeting 32-bit Windows: https://github.com/squeek502/resinator/actions/runs/9204915991/job/25319442772 (but 64-bit Windows and other OSes work fine, even 32-bit targets on other OSes)
There might be multiple bugs involved here, but here's an as-minimal-as-I-could-get-it reproduction of one manifestation of the problem:
```zig
const std = @import("std");
test "limitedWriter basic usage" {
var buf: [4]u8 = undefined;
const fbs = FixedBufferStream{ .buffer = &buf, .pos = 0 };
var limited_stream = LimitedWriter{ .inner_writer = fbs, .bytes_left = 4 };
try std.testing.expectEqual(4, limited_stream.bytes_left);
std.mem.doNotOptimizeAway(&limited_stream);
}
const LimitedWriter = struct {
inner_writer: FixedBufferStream,
bytes_left: u64,
};
const FixedBufferStream = struct {
buffer: []const u8,
pos: usize,
};
```
This passes for me when targeting `x86_64-windows`:
```
> zig test limited_writer.zig -target x86_64-windows
All 1 tests passed.
```
But fails when targeting `x86-windows`:
```
> zig test limited_writer.zig -target x86-windows
expected 4, found 136223752605138948
FAIL (TestExpectedEqual)
Segmentation fault at address 0x0
Panicked during a panic. Aborting.
error: the following test command failed with exit code 3:
C:\Users\Ryan\Programming\Zig\tmp\zig-cache\o\5297f27c52f0325a3ca3d5ec831a5abb\test.exe
```
Importantly, note that `doNotOptimizeAway` is used here because `limited_stream` being `var` is necessary. If `limited_stream` is `const`, then the test passes.
### Expected Behavior
The reproduction test to pass on 32-bit Windows.
1 Like