This change fixes a bug that occured when invoking the changed
function with a "graphic" parameter indicating undefined graphic,
which is defined as "-1" and caused an "array out of bounds" access.
To fix this bug, the function parameter is checked before used.