If an attempt is made to extract texture pack while context is lost, add code to reload texture pack when context is recreated

The most noticable way this issue manifests is when you try to start the game (direct3d9) while a fullscreen application is already running. This causes creating the device to initially fail, but when the context is later recreated (because you toggled out of the fullscreen application), all the textures would appear white because the initial texture pack had attempted to load while context was initially lost.

Of course, the game still crashes when you try to resize the window next (or something else that causes context to get lost), but progress still.
This commit is contained in:
UnknownShadow200 2020-07-27 20:38:41 +10:00
parent 593b581465
commit aa85374894

View file

@ -307,10 +307,15 @@ static cc_result ExtractPng(struct Stream* stream) {
return res;
}
static cc_bool needReload;
static void ExtractFrom(struct Stream* stream, const String* path) {
cc_result res;
Event_RaiseVoid(&TextureEvents.PackChanged);
if (Gfx.LostContext) return;
/* If context is lost, then trying to load textures will just fail */
/* So defer loading the texture pack until context is restored */
if (Gfx.LostContext) { needReload = true; return; }
needReload = false;
if (String_ContainsConst(path, ".zip")) {
res = ExtractZip(stream);
@ -430,7 +435,10 @@ static void OnContextLost(void* obj) {
}
static void OnContextRecreated(void* obj) {
if (!Gfx.ManagedTextures) TexturePack_ExtractCurrent(true);
if (!Gfx.ManagedTextures || needReload) {
TexturePack_ExtractDefault();
TexturePack_ExtractCurrent(false);
}
}
static void OnInit(void) {