Fix current drawable access issue

This commit is contained in:
pandamicro
2021-01-08 21:03:59 +08:00
committed by Yun Hsiao Wu
parent 7cc26a2097
commit bf78abc63c
3 changed files with 10 additions and 5 deletions
@@ -72,6 +72,7 @@ public:
CC_INLINE bool isCommandBufferBegan() const { return _commandBufferBegan; }
CC_INLINE id<MTLCommandBuffer> getMTLCommandBuffer() const { return _mtlCommandBuffer; }
id<CAMetalDrawable> getCurrentDrawable();
void disposeCurrentDrawable();
private:
void bindDescriptorSets();
@@ -74,6 +74,13 @@ id<CAMetalDrawable> CCMTLCommandBuffer::getCurrentDrawable() {
return _currDrawable;
}
void CCMTLCommandBuffer::disposeCurrentDrawable() {
if (_currDrawable) {
[_currDrawable release];
_currDrawable = nil;
}
}
bool CCMTLCommandBuffer::isRenderingEntireDrawable(const Rect &rect, const CCMTLRenderPass *renderPass) {
const int num = renderPass->getColorRenderTargetNums();
if (num == 0) {
@@ -118,11 +125,7 @@ void CCMTLCommandBuffer::end() {
// Secondary command buffer should end encoding here
_commandEncoder.endEncoding();
}
if (_currDrawable) {
[_currDrawable release];
_currDrawable = nil;
}
disposeCurrentDrawable();
if (_autoreleasePool) {
// CC_LOG_INFO("%d CB POOL: %p RELEASED for %p", [NSThread currentThread], _autoreleasePool, this);
@@ -248,6 +248,7 @@ void CCMTLDevice::present() {
_inFlightSemaphore->signal();
}];
[mtlCommandBuffer commit];
cmdBuff->disposeCurrentDrawable();
if (_autoreleasePool) {
// CC_LOG_INFO("POOL: %p RELEASED", _autoreleasePool);