Skip to content

GPU: Prevent null dereference if expected binding is missing #13164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

thatcosmonaut
Copy link
Collaborator

In SDL GPU we defer resource bind calls to draw call time by maintaining an array of resources that the client has requested to bind. The Vulkan and D3D12 backends were storing resource pointers in these arrays. But if the client forgets to bind a resource that the pipeline expects, we end up dereferencing a null pointer. To prevent this, instead of storing the client handles to perform bindings, let's store the actual resource handles that the backend expects, and we can zero out the array of those handles when the pass is done. We can then easily log when an expected binding is missing.

This will end up spamming a lot of errors if the client forgets to bind something. Maybe there's a better way to handle this? On the other hand it's a serious error that should be fixed immediately by the client.

Resolves #13128

@thatcosmonaut thatcosmonaut added this to the 3.2.16 milestone Jun 2, 2025
@thatcosmonaut thatcosmonaut requested a review from slouken June 2, 2025 06:41
@thatcosmonaut
Copy link
Collaborator Author

Restructured the checks so that we can just record keep in gpu.c and avoid the overhead when not in debug mode.

@thatcosmonaut thatcosmonaut merged commit fbba5b2 into libsdl-org:main Jun 2, 2025
41 checks passed
@thatcosmonaut thatcosmonaut deleted the missing_binding_dereference_fix branch June 2, 2025 20:40
thatcosmonaut added a commit that referenced this pull request Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDL3GPU Seg Fault in DrawGPUIndexedPrimitives
2 participants