[a5] al_get_monitor_info giving back crazy sizes
Phrasz

So I am experiencing a weird bug: when I call al_get_monitor_info(0,&Monitor_info); on laptops (the only computers I've seen this issue) the x,y values are CRAZY big.

I only have a limited scope for testing but my main tower (gtx 470), i5/intel laptop, netbook, and raspberry pi are fine. Where as my i5/ATI laptop, and a friend's i5/intel laptop see crazy things like this(line 5):

#SelectExpand
1Display Stats: 2=================================== 3[DEBUGGING] This is the Display Width:1024 and Height:600 4 5[DEBUGGING] This is display 0's info: (8323072, 8545608) - (2686064, 1997880468) 6 7[DEBUGGING] This is Display Scalar: 0.533333 8[DEBUGGING] This is the Monitor aspect ratio: 0.001344 9[DEBUGGING] This is the Default Display aspect ratio: 1.777778 10[DEBUGGING] This is the Display aspect ratio: 1.706667 11[DEBUGGING] This is the Aspect Ratio Y Offset: 11.999985

This is the actual printf's:

#SelectExpand
1printf("\n\n\nDisplay Stats:\n===================================\n"); 2printf("[DEBUGGING] This is the Display Width:%i and Height:%i \n",(int)Display_width,(int)Display_height); 3printf("\n[DEBUGGING] This is display 0's info: (%d, %d) - (%d, %d)", Monitor_info.x1, Monitor_info.y1, Monitor_info.x2, Monitor_info.y2); 4printf("\n[DEBUGGING] This is Display Scalar: %f", DISPLAY_SCALAR); 5printf("\n[DEBUGGING] This is the Monitor aspect ratio: %f", Monitor_Aspect_Ratio); 6printf("\n[DEBUGGING] This is the Default Display aspect ratio: %f", Display_Default_Aspect_Ratio); 7printf("\n[DEBUGGING] This is the Display aspect ratio: %f", Display_Aspect_Ratio); 8printf("\n[DEBUGGING] This is the Aspect Ratio Y Offset: %f",Aspect_Ratio_offset_y);

Anyone ever see an issue like this?

Elias

Where does Monitor_info come from?

[edit:] Ah, you said outside the code. Can you paste the code as well? Maybe it's something like calling it before al_init.

Phrasz

Thanks for the reply Elias.

I could paste the code, but it's a nasty mongrel of macros and functions. I've attached the sections that make sense.

#SelectExpand
1//ENGINE_ALLEGRO_START(); 2if (!al_init()){ 3 printf("\n[ERROR] Could not init Allegro."); 4 return 1; 5} 6//ENGINE_DISPLAY_INSTALL(); 7ALLEGRO_DISPLAY *display; 8ALLEGRO_BITMAP *membitmap; 9ALLEGRO_MONITOR_INFO Monitor_info; 10float DISPLAY_SCALAR; 11float Monitor_Aspect_Ratio; 12float Display_Aspect_Ratio; 13float Display_Default_Aspect_Ratio; 14float Aspect_Ratio_offset_y; 15float Display_Default_width=1920.0; 16float Display_Default_height=1080.0; 17float Display_width; 18float Display_height; 19 20//ENGINE_DISPLAY_GET_MONITOR(); 21al_get_monitor_info(0, &Monitor_info); 22Monitor_Aspect_Ratio = (float)Monitor_info.x2/(float)Monitor_info.y2; 23 24//ENGINE_DISPLAY_START(Monitor_info.x2,Monitor_info.y2); 25Display_width=(float)Monitor_info.x2; 26Display_height=(float)Monitor_info.y2; 27display = al_create_display((int)Display_width, (int)Display_height); 28if (!display){ 29 printf("n[ERROR] Error creating display"); 30 return 1; 31 } 32DISPLAY_SCALAR = Display_Default_width/Display_width; 33Display_Default_Aspect_Ratio = Display_Default_width/Display_Default_height; 34Display_Aspect_Ratio=Display_width/Display_height; 35 36Aspect_Ratio_offset_y=0; 37if(DISPLAY_SCALAR<1.0){ 38 if(Display_Default_Aspect_Ratio!=Display_Aspect_Ratio){ 39 Aspect_Ratio_offset_y=(Display_height-(float)Display_Default_height*DISPLAY_SCALAR)/2.0; 40 } 41} 42else if(DISPLAY_SCALAR>=1.0){ 43 DISPLAY_SCALAR=1.0/DISPLAY_SCALAR; 44 if(Display_Default_Aspect_Ratio!=Display_Aspect_Ratio){ 45 Aspect_Ratio_offset_y=(Display_height-(float)Display_Default_height*DISPLAY_SCALAR)/2.0; 46 } 47} 48al_register_event_source(queue, al_get_display_event_source(display));

Like I said previously, this is a odd bug since it is only occurring on some machines. I am pushing the exe around to the windows boxes, and the performance changes whilst the exe does not.

Elias
Phrasz said:

Display_width=(float)Monitor_info.x2;

Probably you want Display_width=(float)Monitor_info.x2 - Monitor_info.x1; there.

Thomas Fjellstrom
Phrasz said:

Monitor_Aspect_Ratio = (float)Monitor_info.x2/(float)Monitor_info.y2;

These are also wrong, for the same reasons the Display_Width bit is wrong that Elias pointed out.

The monitor info struct gives you a display's geometry in a virtual coordinate space. x1 and y1 are the origin, aka the position of the top left corner, and x2 and y2 are the position of the bottom right corner. x2 and y2 are not the width and height.

Phrasz

Thank you gents! I follow what you guys are saying:

#SelectExpand
1Now to find the proper values: 2Width: x2 - x1 3Height y2 - y1 4 5For most people this will be monitor(0) with values like: 6Width: 1920 - 0 = 1920 7Height 1080 - 0 = 1080

This will catch those crazy people that dual monitor / move monitors in software...etc. Yet, calculating Aspect ratios might be a little trickier now.

However, looking at the original struct/debugging I still get crazy values:

#SelectExpand
1Width: 2686064 - 8323072 = -5637008 2Height 1997880468 - 8545608 = 1989334860

The thing I HAVEN'T done is test for ALL displays, and return ALL monitor modes/info. Granted only laptops are, no 2nd screen, are kicking back values like this...

Thomas Fjellstrom

Can you try listing out all available adapters? That data might be coming back from an adapter that's actually turned off. Or we've botched some win32 code (entirely possible).

Just a hunch though. But if its only happening on a laptop with multiple outputs, combined with the fact that laptop's tend to have really weird setups these days (video switches, optimus, virtu, 3+ outputs, etc), and OEMs aren't known to get drivers or firmware right, the data we get back could be a bit wonky.

Phrasz

Will do. Work has me swamped. I'll do it as soon as I can!

Thomas Fjellstrom

Thanks :) [1]

References

  1. I really posted just so you could post again later without having to edit
Phrasz

So I finally had some time to sit down and go through the problem, and a hunch of mine was correct.

The code I used was:

#SelectExpand
1#include <stdio.h> 2#include <stdlib.h> 3#include "allegro5/allegro.h" 4 5int main(){ 6 ALLEGRO_MONITOR_INFO Monitor_info; 7 float DISPLAY_SCALAR; 8 float Display_Default_width=1920.0; 9 float Display_Default_height=1080.0; 10 float Display_width; 11 float Display_height; 12 13 if (!al_init()){ 14 printf("\n[ERROR] Could not init Allegro."); 15 return 1; 16 } 17 18 al_get_monitor_info(0, & Monitor_info); 19 20 Display_width=(float) Monitor_info.x2; 21 Display_height=(float) Monitor_info.y2; 22 23 DISPLAY_SCALAR = Display_Default_width/ Display_width; 24 25 printf("\n\n\nDisplay Stats:\n===================================\n"); 26 printf("[DEBUGGING] This is the Display Width:%i and Height:%i \n",(int) Display_width,(int) Display_height); 27 printf("[DEBUGGING] This is the Display Width_f:%f and Height_f:%f",Display_width,Display_height); 28 printf("\n[DEBUGGING] This is display 0's info: (%d, %d) - (%d, %d)", Monitor_info.x1, Monitor_info.y1, Monitor_info.x2, Monitor_info.y2); 29 printf("\n[DEBUGGING] This is Display Scalar: %f", DISPLAY_SCALAR); 30 31 return 0; 32}

This still returned the "crazy" results... and I KNEW it shouldn't:

#SelectExpand
1Display Stats: 2=================================== 3[DEBUGGING] This is the Display Width:4200848 and Height:2686760 4[DEBUGGING] This is the Display Width_f:4200848.000000 and Height_f:2686760.000000 5[DEBUGGING] This is display 0's info: (1992429922, 1992776644) - (4200848, 2686760) 6[DEBUGGING] This is Display Scalar: 0.000457

Then it struck me: hp does "dual drivers" for the ATI/Intel:
http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&lc=en&dlc=en&docname=c03048374

I pulled the power cord, switched to the Intel drivers, and to my not surprise I saw:

#SelectExpand
1Display Stats: 2=================================== 3[DEBUGGING] This is the Display Width:1600 and Height:900 4[DEBUGGING] This is the Display Width_f:1600.000000 and Height_f:900.000000 5[DEBUGGING] This is display 0's info: (0, 0) - (1600, 900) 6[DEBUGGING] This is Display Scalar: 1.200000

So now comes the question: does something get added to the allegro code to determine/mitigate this OR do we just need to exception handle for cases where the video cards return something CRAZY?

BTW: the laptops involved with this ALL have these "dual driver" setup...

Thread #612061. Printed from Allegro.cc