glyphcache_init(): bail if we don't have enough off-screen memory to be useful

This commit is contained in:
macallan 2012-11-13 20:29:03 +00:00
parent e51fe9c308
commit 9622d8acf1
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wsdisplay_glyphcache.c,v 1.4 2012/10/04 10:26:32 macallan Exp $ */
/* $NetBSD: wsdisplay_glyphcache.c,v 1.5 2012/11/13 20:29:03 macallan Exp $ */
/*
* Copyright (c) 2012 Michael Lorenz
@ -75,6 +75,14 @@ glyphcache_init(glyphcache *gc, int first, int lines, int width,
buckets = (gc->gc_numcells / 223);
if ((buckets * 223) < gc->gc_numcells)
buckets++;
/*
* if we don't have enough video memory to cache at least a few glyphs
* we stop right here
*/
if (buckets < 1)
return ENOMEM;
gc->gc_buckets = kmem_alloc(sizeof(gc_bucket) * buckets, KM_SLEEP);
if (gc->gc_buckets == NULL) {
aprint_error("%s: can't allocate memory\n", __func__);