ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.57k stars 596 forks source link

[CS 1.6 - Bug] .bmp snapshots are corrupted #681

Closed ghost closed 11 years ago

ghost commented 11 years ago

.tga screenshots are fixed, issue https://github.com/ValveSoftware/halflife/issues/418 was about them, so I open this issue to discuss .bmp snapshots problem.

Windows 7 x64, Widescreen 1366x768, GeForce GT 240, the latest video drivers.

] version
Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
Exe build: 11:45:32 Mar  1 2013 (5971)

Snapshot still doesn't work. -nofbo doesn't help If I DO have Low Quality checked and run fullscreen @ 1360x768 or any lower, everything works.

You can download my corrupted snapshot: https://docs.google.com/file/d/0B-oc73ZQFT19R05qVkg0bjlCV1U/edit?usp=sharing

I was looking for a freeware soft to repair this image and I found this: http://www.irfanview.com/ It worked, and I got this: (repaired and saved to jpeg) Exactly the same result as I had with .tga files, except for the fact that I can not open the original .bmp files at all. I hope this helps.

vjatseslav commented 11 years ago

Can confirm, happens only in fullscreen w/o low video quality opted.

alfred-valve commented 11 years ago

Hmm, I cannot reproduce this locally (using windows 7 and a similar nvidia card). You say that the screenshot command does work for you though? What is your desktop screen resolution and what are you using in game?

ghost commented 11 years ago

@alfred-valve Yes. Screenshot command does work. Desktop screen resolution - 1366x768 In-game screen resolution - 1366x768 Monitor works @ 60Hz (actually 59Hz)

ghost commented 11 years ago

@alfred-valve The bug is not caused by my videocard. I pulled out my GeForce videocard from PC and used iGPU instead (turned it on in BIOS), my CPU is Intel Core i3120, so iGPU is Intel® HD Graphics 2000. It is not fixing the issue.

ghost commented 11 years ago

That's weird. If I set my desktop resolution lower than the native resolution of the monitor (For example, 1360x768, when my native resolution is 1366x768), it also fixes the bug on both iGPU and GeForce GT 240.

ghost commented 11 years ago

More weirdness. When I use my GeForce GT240 videocard. And when I set my desktop resolution lower than the native resolution (1360x768) In addition, the game resolution is higher than the resolution I set (1366x768) In NVIDIA Control Panel I choose "Adjust image settings to..." (Perfomance/Balance/Quality - doesn't matter) the screen is green -nofbo in Launch Options fixes it.

alfred-valve commented 11 years ago

Oh Max, now that is interesting, I have been trying to find a way to reproduce the green screen issue some people are seeing, thanks for providing the details!

ghost commented 11 years ago

After Beta update on March 13 or on March 14 (I'm not sure which one), sometimes snapshot command created not corrupted files filled with black color. After the latest update (when "-glext" argument was added) it is completely broken again.

Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
Exe build: 09:17:33 Mar 14 2013 (5984)
128.0 Mb heap
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: GeForce GT 240/PCIe/SSE2
GL_VERSION: 3.3.0
GL_EXTENSIONS: GL_ARB_arrays_of_arrays GL_ARB_base_instance GL_ARB_blend_func_extended GL_ARB_clear_buffer_object GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage GL_ARB_conservative_depth GL_ARB_copy_buffer GL_ARB_copy_image GL_ARB_debug_output GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_ES2_compatibility GL_ARB_ES3_compatibility GL_ARB_explicit_attrib_location GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_layer_viewport GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_no_attachments GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_get_program_binary GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_internalformat_query2 GL_ARB_invalidate_subdata GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_program_interface_query GL_ARB_provoking_vertex GL_ARB_robust_buffer_access_behavior GL_ARB_robustness GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_separate_shader_objects GL_ARB_shader_bit_encoding GL_ARB_shader_objects GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shading_language_420pack GL_ARB_shading_language_include GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_stencil_texturing GL_ARB_sync GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object GL_ARB_texture_buffer_range GL_ARB_texture_compression GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_gather GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle GL_ARB_texture_view GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback_instanced GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos GL_ATI_draw_buffers GL_ATI_texture_float GL_ATI_texture_mirror_once GL_S3_s3tc GL_EXT_texture_env_add GL_EXT_abgr GL_EXT_bgra GL_EXT_bindable_uniform GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_compiled_vertex_array GL_EXT_Cg_shader GL_EXT_depth_bounds_test GL_EXT_direct_state_access GL_EXT_draw_buffers2 GL_EXT_draw_instanced GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXTX_framebuffer_mixed_formats GL_EXT_framebuffer_multisample_blit_scaled GL_EXT_framebuffer_object GL_EXT_framebuffer_sRGB GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_pixel_buffer_object GL_EXT_point_parameters GL_EXT_provoking_vertex GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_shader_objects GL_EXT_separate_specular_color GL_EXT_shadow_funcs GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_
alfred-valve commented 11 years ago

There should be a line of spew starting with "GL_SIZES" when you launch with "-dev", can you paste that here please

ghost commented 11 years ago

I don't have GL_SIZES in the output if I have -dev -glext in Launch Options. If it's just -dev, I have it.

Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
Exe build: 09:17:33 Mar 14 2013 (5984)
128.0 Mb heap
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: GeForce GT 240/PCIe/SSE2
GL_VERSION: 3.3.0
GL_SIZES:  r:8 g:8 b:8 a:0 depth:24
ghost commented 11 years ago

After Beta update on March 13 or on March 14 (I'm not sure which one), sometimes snapshot command created not corrupted files filled with black color. After the latest update (when "-glext" argument was added) it is completely broken again.

I was wrong. Sometimes I get black snapshots with the latest version. Strange thing, my in-game resolution is 1366x768, but black screens are captured in 640x480

GL_SIZES: r:8 g:8 b:8 a:0 depth:24 why the alpha channel is 0...

alfred-valve commented 11 years ago

The image size matches your window size (if running without -nofbo and not windowed), so it sounds like the game is using a backing FBO at 1366 but your window size is only 640x480... I'll see if I can reproduce this.

Freeman-AM commented 11 years ago

Same problem about screenshots. 1366 native screen resolution

Processeur : Fabricant : AuthenticAMD Vitesse : 2109 MHz 2 processeurs logiques 2 processeurs physiques HyperThreading : Non pris en charge FCMOV : Pris en charge SSE2 : Pris en charge SSE3 : Pris en charge SSSE3 : Pris en charge SSE4a : Non pris en charge SSE41 : Non pris en charge SSE42 : Non pris en charge

Réseau : Vitesse du réseau :

Version du système d'exploitation : Windows XP (32 bits) NTFS : Pris en charge Codes Fournisseur Crypto : Pris en charge 311 0x0 0x0 0x0

Carte vidéo : Pilote : NVIDIA GeForce GT 240

Nom du pilote DirectX : nv4_disp.dll
Version du pilote : 6.14.13.1407
Version du pilote DirectX : 6.14.13.1407
Date du pilote : 10 fév 2013
Profondeur de couleur du bureau : 32 bits par pixel
Taux de rafraîchissement du moniteur : 60 Hz
Carte DirectX : NVIDIA GeForce GT 240
ID fabricant : 0x10de
ID périphérique : 0xca3
Nombre de moniteurs : 1
Nombre de cartes vidéo logiques : 1
Aucun SLI ou Crossfire détecté
Résolution de l'affichage principal : 1366 x 768
Résolution du bureau : 1366 x 768
Taille de l'affichage principal : 16.14" x 9.06" (18.50" diag)
                                        41.0cm x 23.0cm (47.0cm diag)
Bus principal : PCI Express 16x
Mémoire vidéo principale : 512 Mo
Modes MSAA pris en charge : 2x 4x 8x 

Carte son : Périphérique audio : Logitech Wireless Headset

Mémoire : RAM : 2047 Mo

Divers : Langue de l'interface : Français Micro : Not set Type de support : DVD Espace disque total disponible : 629547 Mo Plus grand bloc disponible sur le disque dur : 309564 Mo Date de l'installation du SE : janv. 15 2013 Contrôleur de jeu : None détecté(s)

ghost commented 11 years ago

The image size matches your window size (if running without -nofbo and not windowed), so it sounds like the game is using a backing FBO at 1366 but your window size is only 640x480... I'll see if I can reproduce this.

When I launch the game, I see a small (640x480) white(empty) window, then the game runs normal in fullscreen. It happens really fast, so I recorded a video and captured a frame: image I thought the game creates a window and then resizes it and there's nothing wrong with it.

alfred-valve commented 11 years ago

The game does create a window and then resizes it, but I wonder if that resize is causing you a problem, I have a code change in that may help. Having 0 bits for alpha is fine/good, we don't need transparency through to the desktop :)

Freeman-AM commented 11 years ago

well push a patch download in beta and will see if it work; I'm here ta lest for the next 4 hours.

ghost commented 11 years ago

This issue is very weird. snapshot doesn't work when I launch the game with -sw -w 1366 -h 768, but it works if I use a lower resolution (even 1360x768). It doesn't work in fullscreen no matter what resolution I use. Only

If I DO have Low Quality checked and run fullscreen @ 1360x768 or any lower

helps. Another way to "fix" it:

If I set my desktop resolution lower than the native resolution of the monitor (For example, 1360x768, when my native resolution is 1366x768)

this solution fixes snapshot and it works even in fullscreen without Low Quiality

Freeman-AM commented 11 years ago

This is more a workaround rather than a fix.

ghost commented 11 years ago
] version 
Protocol version 48
Exe version 1.1.2.7/Stdio (cstrike)
Exe build: 14:44:06 Mar 15 2013 (5986)

no, it didn't help :( Are you sure you applied the fix from .tga screenshots issue to this issue?

alfred-valve commented 11 years ago

Yup, it has the code in it. Do you still get a 640x480 screenshot?

alfred-valve commented 11 years ago

Oh, and "screenshot" works fine for you always, it is just snapshot that doesn't work?

ghost commented 11 years ago

Oh, and "screenshot" works fine for you always, it is just snapshot that doesn't work?

yep

ghost commented 11 years ago

I see some resizing anyway. I recorded a video and that's how my game starts frame by frame

1. image image image image

2. image image image

3. image image image image

ghost commented 11 years ago

Do you still get a 640x480 screenshot?

yes

ghost commented 11 years ago

I found a way to reproduce black screen: If the game is minimized and a server plugin executes client_cmd(player, "wait;wait;wait;snapshot"); I get black 640x480 screen

ghost commented 11 years ago

if it helps, snapshot doesn't work in Software mode either

alfred-valve commented 11 years ago

Did the update today help? The fact that is doesn't work in software suggests OS/hardware problem on your end, as those two rendering subsystems use totally different code. Does anyone else reproduce this still?

ghost commented 11 years ago

The update didn't help

] version 
Protocol version 48
Exe version 1.1.2.2/Stdio (valve)
Exe build: 15:37:22 Mar 21 2013 (5992)

.tga screenshots works, .bmp snapshots are corrupted. If I repair a corrupted .bmp file with "IrfanView" (read the first post) I get this: image

As I said, switching to Intel(R) HD Graphics 2000 doesn't help. ( https://github.com/ValveSoftware/halflife/issues/681#issuecomment-14443387 ) And I'm not the only one with the issue:

https://github.com/ValveSoftware/halflife/issues/681#issuecomment-14326256

Can confirm, happens only in fullscreen w/o low video quality opted.

https://github.com/ValveSoftware/halflife/issues/681#issuecomment-14979800

Same problem about screenshots. 1366 native screen resolution Carte DirectX : NVIDIA GeForce GT 240

ghost commented 11 years ago

And again, workarounds I've found:

  1. If I DO have Low Quality checked and run fullscreen @ 1360x768 or any lower
  2. If I set my desktop resolution lower than the native resolution (For example, 1360x768, when my native resolution is 1366x768). Then snapshot works even in fullscreen without Low Quiality

I can install Ubuntu and see if it happens there

alfred-valve commented 11 years ago

I'll try playing around with it when setting a resolution larger than my desktop, that sounds like it causes it for you.

ghost commented 11 years ago

when setting a resolution larger than my desktop

what makes you think I'm using a larger resolution than my native desktop resolution?

ghost commented 11 years ago

OpenGL: image

Software: image

Why they're...rotated(?) in different directions

ghost commented 11 years ago

-full -w 1366 -h 768 +snapshot +exit - .bmp file is corrupted, restored filled with black color -full -w 1360 -h 768 +_set_vid_level 1 +snapshot +exit - .bmp file is not corrupted, still black If do snapshot a little later (when loading is finished), I get normal snapshot

alfred-valve commented 11 years ago

Doing snapshot on the first frame will most likely cause a black screen, so that is expected.

ghost commented 11 years ago

I found a way to fix a corrupted .bmp with a HEX editor. I used HxD to compare a restored file and a corrupted one: Snapshot0000.bmp - corrupted Snapshot0001.bmp - restored with IrfanView image The latest "Offset" in the corrupted file is 00300630 image as you can see, in the restored file there are null bytes in the end of the file, and the latest Offset is 00300C20

When I add those null bytes to the corrupted file, it increases file size and fixes it.

Maybe threre's some break/exception/silent exit error in the save-snapshot function?

ghost commented 11 years ago

Now that is interesting. I installed Half-Life 1.1.1.0 WON, Then I edited hl.exe with a Hex Editor to get access to widescreen resolutions...and I could reproduce the problem! To add widescreen support to Half-Life I opened hl.exe with HxD and found the following string: 20 03 00 00 58 02 00 00. The groups 20 03 and 58 02 represent the resolution 800x600. Available resolutions:

1024x600 - Replace 20 03 with 00 04 and replace 58 02 with 58 02
1280x720 - Replace 20 03 with 00 05 and replace 58 02 with D0 02
1280x800 - Replace 20 03 with 00 05 and replace 58 02 with 20 03
1366x768 - Replace 20 03 with 56 05 and replace 58 02 with 00 03
1440x900 - Replace 20 03 with A0 05 and replace 58 02 with 84 03
1600x900 - Replace 20 03 with 40 06 and replace 58 02 with 84 03
1680x1050 - Replace 20 03 with 90 06 and replace 58 02 with 1A 04
1920x1080 - Replace 20 03 with 80 07 and replace 58 02 with 38 04
1920x1200 - Replace 20 03 with 80 07 and replace 58 02 with B0 04

I replaced 20 03 00 00 58 02 00 00 with 56 05 00 00 00 03 00 00, saved the file and got this: image

Then I took a snapshot and it was corrupted! Repaired .bmp file: image at least it's not rotated

Protocol version 46
Exe version 1.1.1.0
Exe build: 13:25:06 Jun 11 2002 (2056)

.tga screenshot: image

I believe that no one reported this bug before because GoldSource never supported widescreen resolutions up to now. I checked, jpeg and screenshot work fine in Half-Life 2

By the way, bug https://github.com/ValveSoftware/halflife/issues/226 appears only in new - widescreen resolutions. I bet most of the bugs have always existed, and when you have allowed using widescreen resolutions, you have opened Pandora's box.

Will VAC ban me if I edit hl.exe with a HexEditor? I want to try 1366x768 resolution in the latest not-pipe HL:OF.

P.S. If you get Your Half-Life executable has been modified. Please check your system for viruses and re-install Half-Life. exit error, delete hl.dat

UPD. I rechecked. -nofbo fixes the issue for all resolutions, except for 1366x768

UPD2. I checked, D3D and Software mods in WON version are affected too. (if I run @ 1366x768)

johndrinkwater commented 11 years ago

@MaxKorz +1

ghost commented 11 years ago

I was going to install Half-Life: Day One, but I changed my mind and I installed Half-Life Alpha instead.

]version
version 1.07
exe: 09:18:27 sep 4 1997 

snapshot works when resolution is 640x480 image and it doesn't work in resolution 1366x768! Repaired .bmp: image

bonus: Half-Life Uplink image

ghost commented 11 years ago

And deeper! I installed Quake 3 arena demo in steam, launched it and executed

seta r_customwidth "1366"
seta r_customheight "768"
seta r_mode "-1"

in console, then I restarted the game, and executed /screenshot and got this .tga file: (converted to png) image

Please, don't say it's my hardware issue. My hardware is fine. I bought my PC in 2012. And I see this bug only when I use the built-in game function of the snapshot. Seems like only Quake and quake-based games are affected. And there's a lot of reasons why no one reported about this before.

  1. This bug is not very common. Seems like only my resolution (1366x768) has this bug.
  2. Where to report bugs about a very old game?
  3. Widescreen monitors were not popular when Quake was realeased.
  4. You can't set normal(native) widescreen resolution if you don't know how to use console or hex editor.

and super deep quake2 demo, I used Hex Editor to set my native resolution image

ghost commented 11 years ago

QuakeWorld image

GLQuake image

I made my point. The problem is very old and it's very deep in HL engine. And again, it's not my hardware issue, you proved it when you fixed taking .tga screenshots.

hAnnahf commented 11 years ago

@MaxKorz, I'm just taking my hat off to you. I sincerely hope this will be fixed somehow – just for your effort.

ghost commented 11 years ago

@hAnnahf Thank you.

@alfred-valve I did some research. Read this chain: http://zandronum.com/forum/showthread.php?tid=1101 -> http://zandronum.com/tracker/view.php?id=920 -> http://forum.drdteam.org/viewtopic.php?f=25&t=5888&p=52519 ->

It's a problem in the screenshot code. The dimensions given to the bitmap does not correspond to the dimensions of the actual screen, so the rows run on from column to column and you get that slanting effect. You'll notice that 1366x768 is not a "clean" resolution. It doesn't fit in 4:3 (1368x1026 or 1024x768), 5:4 (1365x1092 or 960x768), 16:9 (1360x765), 16:10 (1360x850 or 1232x770) or 17:10 (1360x800 or 1309x770).

Possible fix: http://mancubus.net/svn/gzdoom/trunk?op=revision&rev=1430 http://mancubus.net/svn/gzdoom/trunk?op=revision&rev=1431

  • Fixed: when taking screenshots, change the OpenGL alignment to 1 (from the default 4), because otherwise if the width is not a multiple of 4, OpenGL will add some padding that will mess the entire picture. Once the screenshot is captured, restore default alignment for performance reasons.

http://www.opengl.org/wiki/Common_Mistakes#Texture_upload_and_pixel_reads

Glymbol commented 11 years ago

I still have this problem too, exactly like MaxKorz described it.

alfred-valve commented 11 years ago

http://en.wikipedia.org/wiki/BMP_file_format "The bits representing the bitmap pixels are packed in rows. The size of each row is rounded up to a multiple of 4 bytes (a 32-bit DWORD) by padding." So that is the damn problem, our BMP logic expects nice dimensions on the input buffer (and this is why TGA works, it doesn't have this format requirement). Sigh.

ghost commented 11 years ago

Congratulations :) It is finally fixed!

Glymbol commented 11 years ago

Works for me :) , thanks!

ghost commented 11 years ago

@alfred-valve could you apply the fix to Software mode?