Ensure all wire child objects are destroyed before their device

Destroying a device will implicit destroy all its child objects.
Attempting to use a child object after results in a fatal error.

Bug: dawn:384
Change-Id: I43c27c92cacde759be83cca79ac890f41bac3927
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37002
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Austin Eng
2021-01-13 20:58:18 +00:00
committed by Commit Bot service account
parent 0562802757
commit 8ba0a01d1e
19 changed files with 240 additions and 28 deletions

View File

@@ -59,6 +59,9 @@ namespace dawn_wire { namespace client {
void Client::DestroyAllObjects() {
for (auto& objectList : mObjects) {
ObjectType objectType = static_cast<ObjectType>(&objectList - mObjects.data());
if (objectType == ObjectType::Device) {
continue;
}
while (!objectList.empty()) {
ObjectBase* object = objectList.head()->value();
@@ -69,6 +72,16 @@ namespace dawn_wire { namespace client {
FreeObject(objectType, object);
}
}
while (!mObjects[ObjectType::Device].empty()) {
ObjectBase* object = mObjects[ObjectType::Device].head()->value();
DestroyObjectCmd cmd;
cmd.objectType = ObjectType::Device;
cmd.objectId = object->id;
SerializeCommand(cmd);
FreeObject(ObjectType::Device, object);
}
}
WGPUDevice Client::GetDevice() {
@@ -85,6 +98,8 @@ namespace dawn_wire { namespace client {
result.texture = ToAPI(allocation->object.get());
result.id = allocation->object->id;
result.generation = allocation->generation;
result.deviceId = FromAPI(device)->id;
result.deviceGeneration = DeviceAllocator().GetGeneration(FromAPI(device)->id);
return result;
}