From e2540bf789fd1ca16e6aae79777f21d37e64918a Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 9 Jul 2023 03:17:57 -0500 Subject: [PATCH] renderDX11: fix crash when font tex fails to load issue #1217 --- .../backends/imgui_impl_dx11.cpp | 29 +- .../imgui_patched/backends/imgui_impl_dx11.h | 2 +- papers/multiplayer.md | 402 ++++++++++++++++++ src/engine/platform/sound/ymfm/ymfm_opn.cpp | 1 + src/gui/render/renderDX11.cpp | 3 +- 5 files changed, 423 insertions(+), 14 deletions(-) create mode 100644 papers/multiplayer.md diff --git a/extern/imgui_patched/backends/imgui_impl_dx11.cpp b/extern/imgui_patched/backends/imgui_impl_dx11.cpp index 4977ba2d7..00ecb8e60 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx11.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx11.cpp @@ -339,17 +339,22 @@ static void ImGui_ImplDX11_CreateFontsTexture() subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; bd->pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); - IM_ASSERT(pTexture != nullptr); - // Create texture view - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - ZeroMemory(&srvDesc, sizeof(srvDesc)); - srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvDesc.Texture2D.MipLevels = desc.MipLevels; - srvDesc.Texture2D.MostDetailedMip = 0; - bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView); - pTexture->Release(); + if (pTexture != nullptr) { + // Create texture view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + ZeroMemory(&srvDesc, sizeof(srvDesc)); + srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MostDetailedMip = 0; + bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &bd->pFontTextureView); + pTexture->Release(); + } else { + bd->pFontTextureView=NULL; + bd->pFontSampler=NULL; + return; + } } // Store our identifier @@ -609,13 +614,15 @@ void ImGui_ImplDX11_Shutdown() IM_DELETE(bd); } -void ImGui_ImplDX11_NewFrame() +bool ImGui_ImplDX11_NewFrame() { ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData(); IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX11_Init()?"); if (!bd->pFontSampler) ImGui_ImplDX11_CreateDeviceObjects(); + + return bd->pFontSampler!=NULL; } //-------------------------------------------------------------------------------------------------------- diff --git a/extern/imgui_patched/backends/imgui_impl_dx11.h b/extern/imgui_patched/backends/imgui_impl_dx11.h index cee486f56..5f4dd7f99 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx11.h +++ b/extern/imgui_patched/backends/imgui_impl_dx11.h @@ -19,7 +19,7 @@ struct ID3D11DeviceContext; IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); -IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); +IMGUI_IMPL_API bool ImGui_ImplDX11_NewFrame(); IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); // Use if you want to reset your rendering device without losing Dear ImGui state. diff --git a/papers/multiplayer.md b/papers/multiplayer.md new file mode 100644 index 000000000..75b4cbb47 --- /dev/null +++ b/papers/multiplayer.md @@ -0,0 +1,402 @@ +# multiplayer protocol + +the Furnace protocol is described here. + +# information + +all numbers are little-endian. + +the following fields may be found in "size": +- `f` indicates a floating point number. +- `STR` is a UTF-8 zero-terminated string. +- `CFG` is the same as STR, but contains a config. +- `???` is an array of variable size. +- `S??` is an array of `STR`s. +- `1??` is an array of bytes. +- `2??` is an array of shorts. +- `4??` is an array of ints. + +two player IDs are reserved: +- 0: system +- 1: host (console) + +two usernames are reserved: +- SYSTEM +- HOST + +some characters are not allowed in usernames: 0x00-0x1f, `@`, 0x7f-0x9f, 0xd800-0xdfff, 0xfeff, 0xfffe and 0xffff. + +# header + +size | description +-----|------------------------------------ + 3 | "fur" header + 1 | packet type + 4 | sequence number + +the sequence number always starts at 0. + +# client to server packets (init) + +## 0x00: keep-alive + +this packet keeps a connection alive. +the server shall respond with a packet of type 0x00 (keep-alive). +if the client does not receive any packets during 30 seconds, it will disconnect from the server. +likewise, if the server does not receive any packets during 30 seconds, it will disconnect the client. + +## 0x01: start connection + +size | description +-----|------------------------------------ + 1 | reason + | - 0: information + | - 1: join + 3 | padding + 4 | client version + STR | host name (may be blank) + +after sending, you will receive a packet of type 0x01 (information), 0x02 (disconnect) or 0x03 (authenticate). + +## 0x02: disconnect + +size | description +-----|------------------------------------ + STR | reason + +## 0x03: auth response + +size | description +-----|------------------------------------ + 1 | type + | - 0: open + | - 1: password + | - 2: token + --- | **open response** + STR | username + --- | **password response** + 1 | password type + | - 0: plain text + | - 1: SHA-512 + STR | account name + ??? | password + --- | **token response** + STR | token + +# server to client packets (init) + +## 0x00: keep-alive + +this packet keeps a connection alive. it is a response to a client's keep-alive packet. + +## 0x01: information + +size | description +-----|------------------------------------ + 4 | server version + 2 | online players + | - if it is 65535, this information is concealed. + 2 | maximum players + | - 0 means unlimited. + STR | server version (string) + STR | server name + STR | server description + STR | project name + +the client may send a 0x00 (keep-alive) packet after receiving this one within 5 seconds. +connection is then closed. + +## 0x02: disconnect + +size | description +-----|------------------------------------ + STR | reason + +after being sent, the connection is closed. + +## 0x03: authenticate + +size | description +-----|------------------------------------ + 1 | authentication type + | - 0: open + | - 1: password + | - 2: token + +## 0x04: authentication success + +size | description +-----|------------------------------------ + 4 | player ID + STR | username + CFG | properties + +# client to server packets (session) + +## 0x10: request project + +the client may only send this once every minute. + +## 0x11: participate + +size | description +-----|------------------------------------ + 1 | status + | - 0: spectate + | - 1: join + +## 0x12: send chat message + +size | description +-----|------------------------------------ + STR | message + +## 0x13: send command + +size | description +-----|------------------------------------ + STR | command + 2 | number of arguments + S?? | arguments + +## 0x14: get player list + +no other information required. + +## 0x15: project submission request + +no other information required + +## 0x16: project submission information + +size | description +-----|------------------------------------ + 4 | project size + 32 | SHA-256 sum of project + STR | project name + +this is followed by several 0x17 (project data) packets representing a Furnace song. see [format.md](format.md) for more information. + +## 0x17: project submission data + +size | description +-----|------------------------------------ + 4 | offset + 4 | length + ??? | data... + +the client will send a packet with project size as offset and 0 as length to indicate end of data. +the server subsequently loads the project. + +# server to client packets (session) + +## 0x10: project information + +size | description +-----|------------------------------------ + 4 | project size + 32 | SHA-256 sum of project + STR | project name + +this is followed by several 0x13 (project data) packets representing a Furnace song. see [format.md](format.md) for more information. + +## 0x11: project data + +size | description +-----|------------------------------------ + 4 | offset + 4 | length + ??? | data... + +the server will send a packet with project size as offset and 0 as length to indicate end of data. +the client subsequently loads the project. + +## 0x12: participate status + +size | description +-----|------------------------------------ + 1 | status + | - 0: denied + | - 1: allowed + +## 0x13: message + +size | description +-----|------------------------------------ + 4 | player ID + 8 | time (seconds) + 4 | time (nanoseconds) + 4 | message ID + 1 | type + | - 0: chat, public + | - 1: chat, private + | - 2: notification, info + | - 3: notification, warning + | - 4: notification, urgent + STR | message + +## 0x14: system message + +size | description +-----|------------------------------------ + STR | message + +## 0x15: chat message edited + +size | description +-----|------------------------------------ + 4 | message ID + STR | message + | - an empty message means deleted. + +## 0x16: player list + +size | description +-----|------------------------------------ + 2 | number of players + --- | **player entry** (×players) + 4 | ID + 2 | latency (ms) + 1 | participating? + | - 0: no + | - 1: yes + 1 | status + | - 0: normal + | - 1: away + | - 2: busy + STR | name + STR | IP address + | - if empty, then server is not disclosing IP addresses. + +this is sent after receiving 0x14 (get player list). + +## 0x17: project submission request status + +size | description +-----|------------------------------------ + 1 | status + | - 0: denied + | - 1: allowed + +this is sent after a project submission request is accepted. +if the status is 1, the client shall submit a project. + +## 0x18: project submission complete + +size | description +-----|------------------------------------ + 1 | status + | - 0: error + | - 1: success + STR | additional information + +## 0x19: player joined + +size | description +-----|------------------------------------ + 4 | ID + STR | name + +## 0x1a: player left + +size | description +-----|------------------------------------ + 4 | ID + +# client to server packets (project) + +## 0x20: request orders + +## 0x21: request instrument + +## 0x22: request wavetable + +## 0x23: request sample + +## 0x24: request patterns + +## 0x25: request sub-song + +## 0x26: request song info + +## 0x27: request asset list + +## 0x28: request patchbay + +## 0x29: request grooves + +## 0x30: alter orders + +size | description +-----|------------------------------------ + 4 | transaction ID + +## 0x31: alter instrument + +## 0x32: alter wavetable + +## 0x33: alter sample + +## 0x34: alter pattern + +## 0x35: alter sub-song + +## 0x36: alter song info + +## 0x37: alter asset list + +## 0x38: alter patchbay + +## 0x39: alter grooves + +## 0x3a: alter chips + +## 0x3b: alter chip settings + +# server to client packets (project) + +## 0x20: orders + +## 0x21: instrument + +## 0x22: wavetable + +## 0x23: sample + +## 0x24: pattern + +## 0x25: sub-song + +## 0x26: song info + +## 0x27: asset list + +## 0x28: patchbay + +## 0x29: grooves + +## 0x30: transaction response + +size | description +-----|------------------------------------ + 1 | status + | - 0: error + | - 1: success + | - 2: success but request again + STR | additional information + +# client to server packets (interact) + +## 0x40: engine command + +## 0x41: playback + +# server to client packets (interact) + +## 0x40: engine command + +## 0x41: playback + +# client to server packets (extension) + +# server to client packets (extension) diff --git a/src/engine/platform/sound/ymfm/ymfm_opn.cpp b/src/engine/platform/sound/ymfm/ymfm_opn.cpp index 25d921a95..a8cc198a3 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opn.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_opn.cpp @@ -141,6 +141,7 @@ template bool opn_registers_base::write(uint16_t index, uint8_t data, uint32_t &channel, uint32_t &opmask) { assert(index < REGISTERS); + if (index >= REGISTERS) return false; // writes in the 0xa0-af/0x1a0-af region are handled as latched pairs // borrow unused registers 0xb8-bf/0x1b8-bf as temporary holding locations diff --git a/src/gui/render/renderDX11.cpp b/src/gui/render/renderDX11.cpp index d3bd13069..26bfd0937 100644 --- a/src/gui/render/renderDX11.cpp +++ b/src/gui/render/renderDX11.cpp @@ -290,8 +290,7 @@ void FurnaceGUIRenderDX11::clear(ImVec4 color) { } bool FurnaceGUIRenderDX11::newFrame() { - ImGui_ImplDX11_NewFrame(); - return true; + return ImGui_ImplDX11_NewFrame(); } void FurnaceGUIRenderDX11::createFontsTexture() {