rive-app / rive-app/rive-runtime

Title: D3D11 Access Violation / E_INVALIDARG when calling makeImageTexture (GENERATE_MIPS violation)

Open
#99 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.2k
Forks
121
PR merge metrics
No merged PRs in 30d

Description

Description:
There is a bug in the D3D11 renderer implementation (render_context_d3d_impl.cpp) inside makeImageTexture that causes a hard crash or E_INVALIDARG failure from the GPU driver when attempting to dynamically inject image textures.

The function attempts to initialize a texture using the D3D11_RESOURCE_MISC_GENERATE_MIPS flag while simultaneously passing a single D3D11_SUBRESOURCE_DATA struct to CreateTexture2D.

D3D11_TEXTURE2D_DESC desc = {};
desc.MipLevels = 0; 
desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;

D3D11_SUBRESOURCE_DATA initialData = {};
initialData.pSysMem = pixels;

m_device->CreateTexture2D(&desc, &initialData, &texture);

The Issue:
According to Microsoft's D3D11 specifications, you cannot supply initial data to CreateTexture2D when using GENERATE_MIPS unless you provide an array of SUBRESOURCE_DATA covering every single mip level. Because the current implementation only supplies the base image at Mip Level 0, the driver reads out of bounds and crashes.

Proposed Fix:
The correct DirectX 11 staging pattern for mipmap generation is to:

  1. Call CreateTexture2D with nullptr for the initial data.
  2. Use UpdateSubresource on the device context to push the base image pixels specifically into Mip Level 0.
  3. Call GenerateMips on the resulting ID3D11ShaderResourceView.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in render_context_d3d_impl.cpp at makeImageTexture and inspect how CreateTexture2D receives the texture description and initial data. Follow the D3D11 device-context path for updating the base image and generating mipmaps. Done means dynamically injected image textures no longer produce the GENERATE_MIPS E_INVALIDARG failure or access violation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.