ajaxorg/ace · warning
No valid mapping found in 256 combinations.
Error message
No valid mapping found in 256 combinations.
What it means
A console.warn (not a throw) in FontMetrics when the computed-transform measurement loop exhausts all 256 candidate mappings without finding a valid character-cell measurement (result stays falsy). The function then returns undefined, which can leave glyph-position data missing downstream.
Source
Thrown at src/layer/font_metrics.js:660
var ay = m[1] - target * mp[1];
return [ax, ay, dx * ax, dy * ay, target * mp[2] - m[2]];
});
var res = solve4x4(rows);
var result;
if (res) {
var [x0, y0, w, h] = res;
if (w < 0) { x0 += w; w = -w; }
if (h < 0) { y0 += h; h = -h; }
if (validateSolution(M, x0, y0, w, h, bbox)) {
result = { left: x0, top: y0, width: w, height: h, right: x0 + w, bottom: y0 + h, mappingIdx: i };
break;
}
}
}
if (!result)
console.warn("No valid mapping found in 256 combinations.");
return result;
}
var project = (m, px, py) => {
var k = m[6] * px + m[7] * py + m[8];
return [(m[0] * px + m[1] * py + m[2]) / k, (m[3] * px + m[4] * py + m[5]) / k];
};
/**
* Forward projects the 4 corners of the solution and checks if the
* resulting BBox matches the input bbox.
*/
function validateSolution(M, x, y, w, h, targetBbox) {
var pts = [
[x, y], [x + w, y], [x + w, y + h], [x, y + h]
];
return pts.every(p => {View on GitHub (pinned to 2c1eddc392)
Solutions
- Ensure the editor's CSS (which defines the font for .ace_editor) is loaded before the editor is created
- Avoid fully overriding the editor font-family with a font that fails to load or measures to zero width
- Retest in a real browser — headless environments often lack proper font metrics
- Call editor.renderer.updateCharacterSize() or resize after fonts are ready (document.fonts.ready) to rerun measurement
Example fix
// before
new ace.Editor(...); // custom font 'Foo' not loaded, metrics fail
// after
document.fonts.ready.then(function() { editor.renderer.updateCharacterSize(); }); Defensive patterns
Strategy: validation
Validate before calling
if (!result) {
console.warn('font metrics unavailable; falling back to default char size');
result = { left: 0, top: 0, width: 8, height: 16, right: 8, bottom: 16, mappingIdx: 0 };
} Type guard
function hasValidMetrics(m) { return !!m && typeof m.width === 'number' && m.width > 0 && typeof m.height === 'number' && m.height > 0; } Try / catch
// the library only warns; guard consumers of the measurement: var metrics = measure(); if (!metrics || !(metrics.width > 0)) useDefaultCharSize();
Prevention
- Load the editor stylesheet before instantiating the editor so fonts/CSS are ready
- Wait for document.fonts.ready before measuring when using web fonts
- Avoid headless environments without font rendering for metric-dependent tests
- Don't set the editor font to a font that fails to load or measures at zero size
When it happens
Trigger: Measuring $renderChar... under unusual rendering environments: headless browsers, exotic zoom levels, fonts that fail to load, or canvas/DOM measurement APIs returning degenerate values so every tested mapping fails.
Common situations: CI/headless screenshot tests without real font rendering; zoom/scale combinations in Electron or high-DPI setups; custom CSS overriding the editor's font so measurement characters have zero size.
AI-assisted analysis of ajaxorg/ace@2c1eddc392 (2026-08-30).
Data as JSON: /api/errors/dad18c5356f6b129.
Report an issue: GitHub.