Hi, when I try to call
egui_d3d9::app::EguiDx9::present(&mut self, dev: &IDirect3DDevice9)
I get this error:
thread '<unnamed>' panicked at 'unable to create temporary texture: Error { code: HRESULT(0x8876086C), message: "" }'
Full stacktrace:
17:51:53 [ERROR] thread '<unnamed>' panicked at 'unable to create temporary texture: Error { code: HRESULT(0x8876086C), message: "" }': C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:240
0: backtrace::backtrace::trace<backtrace::capture::impl$1::create::closure_env$0>
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\backtrace-0.3.67\src\backtrace\mod.rs:53
1: backtrace::capture::Backtrace::create
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\backtrace-0.3.67\src\capture.rs:176
2: backtrace::capture::Backtrace::new
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\backtrace-0.3.67\src\capture.rs:140
3: backtrace::capture::impl$8::default
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\backtrace-0.3.67\src\capture.rs:410
4: alloc::vec::Vec::append_elements
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\alloc\src\vec\mod.rs:1942
5: alloc::vec::spec_extend::impl$4::spec_extend
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\alloc\src\vec\spec_extend.rs:55
6: alloc::vec::Vec::extend_from_slice
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\alloc\src\vec\mod.rs:2386
7: alloc::string::String::push_str
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\alloc\src\string.rs:926
8: alloc::string::impl$65::write_str
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\alloc\src\string.rs:2861
9: core::fmt::impl$0::write_str<alloc::string::String>
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:199
10: core::fmt::write
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:1118
11: core::fmt::Formatter::write_fmt
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:1548
12: windows::core::strings::hstring::impl$9::fmt
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.48.0\src\core\strings\hstring.rs:149
13: windows::core::strings::hstring::HSTRING::is_empty
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.48.0\src\core\strings\hstring.rs:19
14: core::fmt::builders::impl$3::finish::closure$0
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\builders.rs:226
15: core::result::Result::and_then
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\result.rs:1319
16: core::fmt::builders::DebugStruct::finish
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\builders.rs:225
17: core::ptr::drop_in_place<windows::core::strings::hstring::HSTRING>
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2\library\core\src\ptr\mod.rs:491
18: core::fmt::impl$53::fmt<dyn$<core::fmt::Debug> >
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:2258
19: core::fmt::rt::Argument::fmt
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\rt.rs:138
20: core::fmt::write
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:1094
21: core::fmt::Write::write_fmt
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\fmt\mod.rs:192
22: std::panicking::begin_panic_handler::impl$0::fill::closure$0
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\std\src\panicking.rs:544
23: core::option::Option::get_or_insert_with
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\core\src\option.rs:1651
24: std::panicking::begin_panic_handler::PanicPayload::fill
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\std\src\panicking.rs:542
25: std::panicking::begin_panic_handler::impl$1::get
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\std\src\panicking.rs:560
26: <unknown>
27: windows::core::error::GetErrorInfo
at C:\Users\tobii\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.48.0\src\core\error.rs:154
28: std::panicking::begin_panic_handler::closure$0
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2/library\std\src\panicking.rs:582
29: <unknown>
30: enum2$<core::result::Result<tuple$<>,windows::core::error::Error> >::expect<tuple$<>,windows::core::error::Error>
at /rustc/87b1f891ea76713462cfc5a15137a8fe2b24ecc2\library\core\src\result.rs:1033
31: egui_d3d9::texman::create_temporary_texture
at C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:240
32: egui_d3d9::texman::new_texture_from_buffer
at C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:263
33: egui_d3d9::texman::TextureManager::create_new_texture
at C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:88
34: egui_d3d9::texman::impl$1::process_set_deltas::closure$0
at C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:58
35: egui_d3d9::texman::TextureManager::process_set_deltas
at C:\Users\tobii\.cargo\git\checkouts\egui-d3d9-6163636d01cb9325\2fa7541\egui-d3d9\src\texman.rs:41
36: SE_GetProcAddressForCaller
37: MsgWaitForMultipleObjectsEx
38: NtUserSetWindowLong
39: <unknown>
The error seems to come from here: https://github.com/unknowntrojan/egui-d3d9/blob/b28a661163db170ebd996be59b9b87e267406e89/egui-d3d9/src/texman.rs#LL241C21-L241C21
But I have no idea why that would fail, or how to debug it.
According to the docs, at https://learn.microsoft.com/en-us/windows/win32/api/d3d9/nf-d3d9-idirect3ddevice9-createtexture
In Windows Vista CreateTexture can create a texture from a system memory pointer allowing the application >more flexibility over the use, allocation and deletion of the system memory. For example, an application >could pass a GDI system memory bitmap pointer and get a Direct3D texture interface around it. Using a system >memory pointer with CreateTexture has the following restrictions:
- The pitch of the texture must be equal to the width multiplied by the number of bytes per pixel.
- Only textures with a single mipmap level are supported. The Levels argument must be 1.
- The Pool argument must be D3DPOOL_SYSTEMMEM.
- The pSharedHandle argument must be a valid pointer to a buffer that can hold the system memory point; >*pSharedHandle must be a valid pointer to system memory with a size in bytes of texture width * texture >height * bytes per pixel of the texture format.
But I think that is all correct in this case.
Here is the rest of the code:
use egui::Context;
use egui_d3d9::EguiDx9;
use std::sync::Once;
use windows::Win32::{
Foundation::{HWND, LPARAM, LRESULT, WPARAM},
Graphics::Direct3D9::IDirect3DDevice9,
UI::WindowsAndMessaging::{CallWindowProcW, SetWindowLongPtrA, GWLP_WNDPROC, WNDPROC},
};
static mut APP: Option<EguiDx9<i32>> = None;
/// Original WNDPROC, so we can do CallWindowProcW(...) with it
static mut FN_ORG_WNDPROC: WNDPROC = None;
fn hello_ui(ctx: &Context, _frame: &mut i32) {
log::trace!("I made it to hello_ui(..., _frame={_frame})"); // it reaches this line...
egui::containers::Window::new("Main").show(ctx, |ui| {
ctx.settings_ui(ui);
ui.label("Hello world!");
//ui.label(egui::RichText::new("Hello world").color(egui::Color32::WHITE));
});
log::trace!("I made past egui::containers::Window::new(...)!"); // and this one... But after that it crashes?
}
/// draw() gets called right before the original IDirect3DDevice9::Present() is called.
pub fn draw(dev: &IDirect3DDevice9, hwnd: HWND) {
log::trace!("I made it to draw({hwnd:?})");
static INIT: Once = Once::new();
INIT.call_once(move || {
unsafe {
APP = Some(EguiDx9::init(dev, hwnd, hello_ui, 0, true));
FN_ORG_WNDPROC = std::mem::transmute(SetWindowLongPtrA(
hwnd,
GWLP_WNDPROC,
hk_wnd_proc as usize as _,
));
};
});
let app = unsafe { APP.as_mut().unwrap() };
app.present(dev); //Crashes
log::trace!("I made it past app.present(dev))"); // doesnt reach this line I think
}
unsafe extern "stdcall" fn hk_wnd_proc(
hwnd: HWND,
msg: u32,
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
//This is okay because APP gets set before hooking this WNDPROC
APP.as_mut().unwrap().wnd_proc(msg, wparam, lparam);
CallWindowProcW(FN_ORG_WNDPROC, hwnd, msg, wparam, lparam)
}
[EDIT] Full code here: https://github.com/tobii-dev/blur-hooks-rs/blob/2f96fcb9d54a2dbfae2aca9258f4ccf5e62aefbb/src/gui/console.rs#L40
In the trace log file, I can see all the traces hit, except "I made it past app.present(dev))".
Any help testing or debugging this would be ๐ฏ