Skip to content

Commit bc5cf73

Browse files
mmMemoryGPU - don't print verbose error from missing GPU
When a MRenderer cannot be found, lets just print that and allow the command to continue successfully. An MRenderer is probably not found if Maya is running in a batch-mode without any GPU, for example in a Docker container, or the Linux machine is not running a X11 display server.
1 parent 9e4138c commit bc5cf73

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

python/mmSolver/tools/imagecache/_lib/query_resources.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@
3131

3232

3333
def get_gpu_memory_total_bytes():
34-
return int(maya.cmds.mmMemoryGPU(query=True, total=True))
34+
total_bytes = maya.cmds.mmMemoryGPU(query=True, total=True)
35+
if total_bytes is None:
36+
return 0
37+
return int(total_bytes)
3538

3639

3740
def get_gpu_memory_used_bytes():
38-
return int(maya.cmds.mmMemoryGPU(query=True, used=True))
41+
used_bytes = maya.cmds.mmMemoryGPU(query=True, used=True)
42+
if used_bytes is None:
43+
return 0
44+
return int(used_bytes)
3945

4046

4147
def get_cpu_memory_total_bytes():

src/mmSolver/cmd/MMMemoryGPUCmd.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include <maya/MStringArray.h>
4242
#include <maya/MSyntax.h>
4343

44+
// Maya Viewport 2.0
45+
#include <maya/MViewport2Renderer.h>
46+
4447
// MM Solver
4548
#include <mmcolorio/lib.h>
4649

@@ -159,6 +162,17 @@ MStatus MMMemoryGPUCmd::doIt(const MArgList &args) {
159162
MStatus status = parseArgs(args);
160163
CHECK_MSTATUS_AND_RETURN_IT(status);
161164

165+
// When running without a GPU (for example in a Docker container),
166+
// don't Spam the user with warnings and errors that the MRenderer
167+
// cannot be found.
168+
const MHWRender::MRenderer *renderer = MHWRender::MRenderer::theRenderer();
169+
if (!renderer) {
170+
MMSOLVER_MAYA_WRN(
171+
"mmMemoryGPU: Failed to get Maya MRenderer! "
172+
"Maybe running on a machine without a GPU?");
173+
return MStatus::kSuccess;
174+
}
175+
162176
size_t bytes_value = 0;
163177
if (m_memory_total) {
164178
status = mmmemorygpu::memory_total_size_in_bytes(bytes_value);

0 commit comments

Comments
 (0)