Decrement context ref count as a last action in program destructor.

- There are various calls to device inside destructor.
- Memory manager is protected via device , which is protected by context.
- If context is destroyed it means that device may be destroyed, which means
that memory manager may be destroyed and we have a seg fault.

Change-Id: I2cb6a69790f53bf2c9fba89160078b009e105574
This commit is contained in:
Mrozek, Michal
2018-06-28 09:01:51 +02:00
parent 887df5a90d
commit b7545f1401
2 changed files with 19 additions and 3 deletions

View File

@ -2941,3 +2941,19 @@ TEST(SimpleProgramTests, givenDefaultProgramWhenSetDeviceIsCalledThenDeviceIsSet
pProgram.SetDevice(nullptr);
EXPECT_EQ(nullptr, pProgram.getDevicePtr());
}
TEST(ProgramDestructionTests, givenProgramUsingDeviceWhenItIsDestroyedAfterPlatfromCleanupThenItIsCleanedUpProperly) {
constructPlatform();
platformImpl->initialize();
auto device = platformImpl->getDevice(0);
MockContext *context = new MockContext(device, false);
MockProgram *pProgram = new MockProgram(context, false);
auto globalAllocation = device->getMemoryManager()->allocateGraphicsMemory(MemoryConstants::pageSize);
pProgram->setGlobalSurface(globalAllocation);
platformImpl.reset(nullptr);
EXPECT_EQ(1, device->getRefInternalCount());
EXPECT_EQ(1, pProgram->getRefInternalCount());
context->decRefInternal();
pProgram->decRefInternal();
}