Skip to content

Commit 6e1636d

Browse files
committed
Vulkan: guard recreateVkSurface, refer axmolengine#3022
1 parent f51d0c6 commit 6e1636d

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

axmol/platform/android/RenderViewImpl-android.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ void RenderViewImpl::recreateVkSurface(bool needUpdateRenderSurface)
130130
.width = static_cast<int>(_windowSize.width),
131131
.height = static_cast<int>(_windowSize.height),
132132
.createFunc = _createSurface};
133+
if (!createInfo.window)
134+
{
135+
AXLOGE("recreateVkSurface: ANativeWindow is null, skip");
136+
return;
137+
}
138+
if (createInfo.width == 0 || createInfo.height == 0)
139+
{
140+
AXLOGW("recreateVkSurface: window size is 0, skip");
141+
return;
142+
}
133143
auto driver = static_cast<ax::rhi::vk::DriverImpl*>(axdrv);
134144
bool ok = driver->recreateSurface(createInfo);
135145
if (!ok)

axmol/platform/android/jni/AxmolPlayerJni.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,24 @@ JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeOnSurfaceCreated(JNI
8181
{
8282
if (s_nativeWindow)
8383
ANativeWindow_release(s_nativeWindow);
84-
s_nativeWindow = ANativeWindow_fromSurface(env, surface);
84+
85+
s_nativeWindow = ANativeWindow_fromSurface(env, surface);
86+
if (s_nativeWindow == nullptr) {
87+
AXLOGW("ANativeWindow_fromSurface failed: surface={}, "
88+
"windowSize=({} x {}), threadId={}",
89+
fmt::ptr(surface),
90+
static_cast<int>(w),
91+
static_cast<int>(h),
92+
(long)gettid());
93+
return;
94+
}
95+
96+
AXLOGI("ANativeWindow_fromSurface success: window={}, "
97+
"size=({} x {})",
98+
fmt::ptr(s_nativeWindow),
99+
static_cast<int>(w),
100+
static_cast<int>(h));
101+
85102
auto director = ax::Director::getInstance();
86103
auto renderView = director->getRenderView();
87104
if (!renderView)

axmol/rhi/vulkan/DriverVK.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ bool DriverImpl::initializeFactory()
288288
else
289289
{
290290
AXLOGE("Unsupported window platform: neither WAYLAND_DISPLAY nor DISPLAY found");
291-
assert(false);
291+
return false;
292292
}
293293
#endif
294294

0 commit comments

Comments
 (0)