-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mac: gg.draw_text()
Font size + long string causes text corruption (missing characters)
#20457
Comments
Can confirm that this seems to be a MacOS issue, as I just tested and there is no bug on my Windows PC. ![]() V full version: V 0.4.4 be4f717 getwd: C:\Users\Samuel\Documents vroot: OK, value: C:\Users\Samuel\Documents\GitHub\v Git version: git version 2.37.1.windows.1 CC version: Error: 'cc' is not recognized as an internal or external command, thirdparty/tcc status: thirdparty-windows-amd64 b99a453d |
gg.draw_text()
Font size + long string causes text corruption (missing characters)gg.draw_text()
Font size + long string causes text corruption (missing characters)
Yeah I am using a highdpi monitor so expanding out in your case makes sense. I think my troubles lie in the darwin specific text functions in vlib.gg. void darwin_draw_string(int x, int y, string s, gx__TextCfg cfg) {
NSFont* font = [NSFont userFontOfSize:0]; // cfg.size];
// # NSFont* font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
if (cfg.mono) {
// # font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
font = [NSFont fontWithName:@"Menlo" size:cfg.size - 5];
}
if (cfg.bold) {
font = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
}
NSDictionary* attr = @{
NSForegroundColorAttributeName : nscolor(cfg.color),
// NSParagraphStyleAttributeName: paragraphStyle,
NSFontAttributeName : font,
};
[nsstring(s) drawAtPoint:NSMakePoint(x, y - 15) withAttributes:attr];
}
int darwin_text_width(string s) {
// println('text_width "$s" len=$s.len')
NSString* n = @"";
if (s.len == 1) {
// println('len=1')
n = [NSString stringWithFormat:@"%c", s.str[0]];
} else {
n = nsstring(s);
}
/*
# if (!defaultFont){
# defaultFont = [NSFont userFontOfSize: ui__DEFAULT_FONT_SIZE];
# }
# NSDictionary *attrs = @{
# NSFontAttributeName: defaultFont,
# };
*/
NSSize size = [n sizeWithAttributes:nil];
// # printf("!!!%f\n", ceil(size.width));
return (int)(ceil(size.width));
} |
BTW this is going to sound very silly but I was trying to run this example on my linux vm (stock Debian Arm) and I could not for the life of me get the thing running. I blindly installed a bunch of libs to make it sorta compile but at runtime I get a GLX crash:
What libs do I need to install for linux to use sokol/gg/gx ? :) |
This was a false lead. After some quick debugging with some print statements I found sokol/gg is not using the macOS native pipeline, so the bug isn't anything to do with the objc stuff. I'll start looking into the fontstash wrapper, although the on the c side of things the repo is 10/11 years dry so no wonder things get weird with MacOS. There also seems to be like.. a completely different version of fontstash out there which seems to have provisions for differentiating macOS OpenGL/vs GL libraries ?? |
Nothing special, except that you do need a video driver that supports OpenGL 3.3+. |
Describe the bug
If the string that is being passed to the
draw_text()
function is above a certain font size the text to be drawn for that font size will be corrupted (missing characters). The threshold for corruption seems to be based on the string length. Smaller length strings wont corrupt until higher font sizes.Only tested on MacOS Arm so far, will try again on my x86 Windows machine when I have the time unless someone beats me to it!Reproduction Steps
Expected Behavior
I expect there to be no corrupted text in the above example.
I have attached the following which is expected output from 10 to 50 (which doesn't corrupt):
![Screenshot 2024-01-10 at 14 31 14](https://private-user-images.githubusercontent.com/34013162/295439507-b9e0a04f-c201-4dcf-958f-70254a8c0d2a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2ODgwNTAsIm5iZiI6MTcyMDY4Nzc1MCwicGF0aCI6Ii8zNDAxMzE2Mi8yOTU0Mzk1MDctYjllMGEwNGYtYzIwMS00ZGNmLTk1OGYtNzAyNTRhOGMwZDJhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzExVDA4NDkxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRjYTM5YWUwY2RiY2E0NWVhMjM5ZjdiNzRlNjQwYjU3MDg1MmJmNTlkNzMwODkxZTM5ZTIzYzU1MjcxN2E0OTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rkpy7O-6Q0LErIHkiQvDMBC1nJh5vHtJUAedzFu8yIk)
Current Behavior
If plotting from 10 to 100 we get this:
![Screenshot 2024-01-10 at 14 31 53](https://private-user-images.githubusercontent.com/34013162/295439818-970f1483-69bc-400b-9408-8c040022e494.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2ODgwNTAsIm5iZiI6MTcyMDY4Nzc1MCwicGF0aCI6Ii8zNDAxMzE2Mi8yOTU0Mzk4MTgtOTcwZjE0ODMtNjliYy00MDBiLTk0MDgtOGMwNDAwMjJlNDk0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzExVDA4NDkxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWIxZDk5MmU3NGM3ZjE1NzdkZjA2MjQ0MGIzZjU3ZTgyZGZkODUzNDdkZGNhY2Y2MmM4ZWRmY2VhNGJhNjE5ZWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.K6bRoqFR1BQ37TIiO6Y6dC3aIi__37YxOvle7l3ZvnE)
Refining thresholds it seems to be about 63-64 which triggers this corruption. You can see that other text (like the "Font size: X") is corrupted as well even though it is kept at
![Screenshot 2024-01-10 at 14 30 50](https://private-user-images.githubusercontent.com/34013162/295440048-2867c281-5fef-4412-95ee-c3f78996e094.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2ODgwNTAsIm5iZiI6MTcyMDY4Nzc1MCwicGF0aCI6Ii8zNDAxMzE2Mi8yOTU0NDAwNDgtMjg2N2MyODEtNWZlZi00NDEyLTk1ZWUtYzNmNzg5OTZlMDk0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzExVDA4NDkxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEzOTNlOWFiMmY4OGJlNjkyMDI4M2E1OTQ4N2U4NWVhYWUzNmYxZDkyZWQ5YjFmYWM2OTc3NWNhNmYzM2JiNDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.IKlRx34-FxkCGxGgMN27EHryPOwwNmSM7qANPmdXaII)
size: 50
the whole time.Using smaller length text string:
![Screenshot 2024-01-10 at 14 44 02](https://private-user-images.githubusercontent.com/34013162/295442904-f84b8884-5bd5-434f-a8c1-cb468c646ee1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2ODgwNTAsIm5iZiI6MTcyMDY4Nzc1MCwicGF0aCI6Ii8zNDAxMzE2Mi8yOTU0NDI5MDQtZjg0Yjg4ODQtNWJkNS00MzRmLWE4YzEtY2I0NjhjNjQ2ZWUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzExVDA4NDkxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlhMTlmMWI1NjNmNDM2MzI3MDJmZGMyZTBkZDhlYWY0M2YxOTJlMDdiYjE2NWMzMjY2NWE4MDA5NmEyYTZkMTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Vk_bvmxcEPlqJRBdj6gNYQfwmLjTabLUkSZX0nzRkvw)
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.3 e19b2dd
Environment details (OS name and version, etc.)
V full version: V 0.4.3 e19b2dd
OS: macos, macOS, 14.1.2, 23B92
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro
getwd: /Users/samuel/Desktop/v_test
vexe: /Users/samuel/Documents/GitHub/v/v
vexe mtime: 2024-01-05 05:25:03
vroot: OK, value: /Users/samuel/Documents/GitHub/v
VMODULES: OK, value: /Users/samuel/.vmodules
VTMP: OK, value: /tmp/v_501
Git version: git version 2.39.0
Git vroot status: 0.4.2-732-ge19b2dd4 (35 commit(s) behind V master)
.git/config present: true
CC version: Apple clang version 15.0.0 (clang-1500.1.0.2.5)
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: