KnownObject: Make it an error to request ID 0

WebGPU error handling assumes non-optional objects point to valid
objects. The wire code wasn't updated to produce an error when ID 0 is
requested in the non-optional case.

BUG=chromium:934360

Change-Id: I203d2ec864dabe0e76109e1932fc31cbf26291d7
Reviewed-on: https://dawn-review.googlesource.com/c/4980
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-02-25 09:49:00 +00:00 committed by Commit Bot service account
parent 8deadd8d02
commit b92fa10557
1 changed files with 8 additions and 6 deletions

View File

@ -60,12 +60,14 @@ namespace dawn_wire { namespace server {
using Data = ObjectData<T>; using Data = ObjectData<T>;
KnownObjects() { KnownObjects() {
// Pre-allocate ID 0 to refer to the null handle. // Reserve ID 0 so that it can be used to represent nullptr for optional object values
Data nullObject; // in the wire format. However don't tag it as allocated so that it is an error to ask
nullObject.handle = nullptr; // KnownObjects for ID 0.
nullObject.valid = true; Data reservation;
nullObject.allocated = true; reservation.handle = nullptr;
mKnown.push_back(nullObject); reservation.valid = false;
reservation.allocated = false;
mKnown.push_back(reservation);
} }
// Get a backend objects for a given client ID. // Get a backend objects for a given client ID.