Skip to content

Commit

Permalink
Merge pull request #30 from neico/improve-error-logging
Browse files Browse the repository at this point in the history
Improve error logging
  • Loading branch information
Borf authored Jan 13, 2025
2 parents 85e02a8 + 17ddc30 commit ac0c6fa
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 206 deletions.
36 changes: 36 additions & 0 deletions BrowEdit3.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity
type="win32"
name="borf.BrowEdit3"
version="3.0.0.0"
processorArchitecture="*"
/>
<description>BrowEdit 3</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 and Windows 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<!-- <ws2:longPathAware>true</ws2:longPathAware> -->
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
9 changes: 7 additions & 2 deletions BrowEdit3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<ClCompile Include="browedit\ModelEditor.cpp" />
<ClCompile Include="browedit\Node.cpp" />
<ClCompile Include="browedit\NodeRenderer.cpp" />
<ClCompile Include="browedit\util\Console.cpp" />
<ClCompile Include="browedit\util\FileIO.cpp" />
<ClCompile Include="browedit\util\Util.cpp" />
<ClCompile Include="browedit\windows\CinematicModeWindow.cpp" />
Expand Down Expand Up @@ -204,6 +205,7 @@
<ClInclude Include="browedit\shaders\RsmShader.h" />
<ClInclude Include="browedit\shaders\SimpleShader.h" />
<ClInclude Include="browedit\shaders\WaterShader.h" />
<ClInclude Include="browedit\util\Console.h" />
<ClInclude Include="browedit\util\FileIO.h" />
<ClInclude Include="browedit\util\glfw_keycodes_to_string.h" />
<ClInclude Include="browedit\util\ResourceManager.h" />
Expand Down Expand Up @@ -271,6 +273,9 @@
<None Include="docs\ObjectEdit.md" />
<None Include="docs\Readme.md" />
</ItemGroup>
<ItemGroup>
<Manifest Include="BrowEdit3.manifest" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
Expand Down Expand Up @@ -314,7 +319,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NOMINMAX;GRF_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;GRF_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>lib/imgui/;lib/glfw-3.3.8/include;lib/grflib;lib/zlib;lib/sfl;lib/glm;lib/glad/include;$(SolutionDir);lib/bugtrap;lib/magic_enum/include;lib/imGuIZMO.quat/imGuIZMO.quat</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
Expand All @@ -340,7 +345,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NOMINMAX;GRF_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;GRF_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>lib/imgui/;lib/glfw-3.3.8/include;lib/grflib;lib/zlib;lib/sfl;lib/glm;lib/glad/include;$(SolutionDir);lib/bugtrap;lib/magic_enum/include;lib/imGuIZMO.quat/imGuIZMO.quat</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand Down
11 changes: 11 additions & 0 deletions BrowEdit3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@
<ClCompile Include="browedit\actions\LightmapChangeAction.cpp">
<Filter>browedit\actions</Filter>
</ClCompile>
<ClCompile Include="browedit\util\Console.cpp">
<Filter>browedit\util</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\imgui\imgui.h">
Expand Down Expand Up @@ -747,6 +750,9 @@
<ClInclude Include="browedit\actions\LightmapChangeAction.h">
<Filter>browedit\actions</Filter>
</ClInclude>
<ClInclude Include="browedit\util\Console.h">
<Filter>browedit\util</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="BrowEdit3.rc">
Expand Down Expand Up @@ -821,4 +827,9 @@
<Filter>docs\formats</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Manifest Include="BrowEdit3.manifest">
<Filter>Resource Files</Filter>
</Manifest>
</ItemGroup>
</Project>
120 changes: 65 additions & 55 deletions browedit/BrowEdit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <Windows.h> //to remove ugly warning :(
#include "BrowEdit.h"
#include "Version.h"
#include <GLFW/glfw3.h>
Expand Down Expand Up @@ -28,6 +27,7 @@
#include <browedit/components/RsmRenderer.h>
#include <browedit/util/FileIO.h>
#include <browedit/util/Util.h>
#include <browedit/util/Console.h>
#include <browedit/util/ResourceManager.h>
#include <browedit/util/glfw_keycodes_to_string.h>

Expand All @@ -36,8 +36,10 @@


#ifdef _WIN32
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#include <Windows.h> //to remove ugly warning :(

extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#endif

#ifndef _DEBUG
Expand All @@ -55,13 +57,14 @@ static void SetupExceptionHandler()
BT_SetSupportURL("https://discord.gg/bQaj5dKtbV");
}


int main()
{
#ifndef _DEBUG
SetupExceptionHandler();
#endif

ConsoleInject consoleInjector;

std::cout << R"V0G0N( ';cllllllc:,
,lodddddddddddoc,
cdddddddddddoddddo:
Expand Down Expand Up @@ -99,6 +102,7 @@ int main()
)V0G0N" << std::endl;

BrowEdit().run();
}

Expand Down Expand Up @@ -1018,65 +1022,71 @@ void BrowEdit::ShowNewMapPopup()

void fixEffectPreviews()
{
for (auto entry : std::filesystem::directory_iterator("data\\texture\\effect"))
try
{
if (entry.path().string().find(".png") != std::string::npos)
continue;
if (entry.path().string().find(".gif") == std::string::npos)
continue;
std::istream* is = util::FileIO::open(entry.path().string());
std::cout << entry.path().string() << std::endl;
if (!is)
{
std::cerr << "Texture: Could not open " <<entry.path().string() << std::endl;
return;
}
is->seekg(0, std::ios_base::end);
std::size_t len = is->tellg();
if (len <= 0 || len > 100 * 1024 * 1024)
for (auto entry : std::filesystem::directory_iterator("data\\texture\\effect", std::filesystem::directory_options::follow_directory_symlink | std::filesystem::directory_options::skip_permission_denied))
{
std::cerr << "Texture: Error opening texture " << entry.path().string() << ", file is either empty or too large" << std::endl;
if (entry.path().string().find(".png") != std::string::npos)
continue;
if (entry.path().string().find(".gif") == std::string::npos)
continue;
std::istream* is = util::FileIO::open(entry.path().string());
std::cout << entry.path().string() << std::endl;
if (!is)
{
std::cerr << "Texture: Could not open " <<entry.path().string() << std::endl;
return;
}
is->seekg(0, std::ios_base::end);
std::size_t len = is->tellg();
if (len <= 0 || len > 100 * 1024 * 1024)
{
std::cerr << "Texture: Error opening texture " << entry.path().string() << ", file is either empty or too large" << std::endl;
delete is;
return;
}
char* buffer = new char[len];
is->seekg(0, std::ios_base::beg);
is->read(buffer, len);
delete is;
return;
}
char* buffer = new char[len];
is->seekg(0, std::ios_base::beg);
is->read(buffer, len);
delete is;

int width, height, frameCount, comp;
int* delays;
auto data = stbi_load_gif_from_memory((stbi_uc*)buffer, (int)len, &delays, &width, &height, &frameCount, &comp, 4);
if (!data)
continue;
int bestFrame = 0;
int bestFrameCount = 0;
for (int f = 0; f < frameCount; f++)
{
auto d = data + (width * height * 4) * f;
int frameIntensity = 0;
for (int x = 0; x < width; x++)

int width, height, frameCount, comp;
int* delays;
auto data = stbi_load_gif_from_memory((stbi_uc*)buffer, (int)len, &delays, &width, &height, &frameCount, &comp, 4);
if (!data)
continue;
int bestFrame = 0;
int bestFrameCount = 0;
for (int f = 0; f < frameCount; f++)
{
for (int y = 0; y < height; y++)
auto d = data + (width * height * 4) * f;
int frameIntensity = 0;
for (int x = 0; x < width; x++)
{
frameIntensity += d[(x + width * y) * 4 + 0];
frameIntensity += d[(x + width * y) * 4 + 1];
frameIntensity += d[(x + width * y) * 4 + 2];
for (int y = 0; y < height; y++)
{
frameIntensity += d[(x + width * y) * 4 + 0];
frameIntensity += d[(x + width * y) * 4 + 1];
frameIntensity += d[(x + width * y) * 4 + 2];
}
}
if (frameIntensity > bestFrameCount)
{
bestFrameCount = frameIntensity;
bestFrame = f;
}
}
if (frameIntensity > bestFrameCount)
{
bestFrameCount = frameIntensity;
bestFrame = f;
}
}
stbi_write_png((entry.path().string() + ".png").c_str(), width, height, 4, data + bestFrame * width * height*4, 0);
stbi_write_png((entry.path().string() + ".png").c_str(), width, height, 4, data + bestFrame * width * height*4, 0);

std::cout << "Best frame is " << bestFrame << std::endl;
std::cout << "Best frame is " << bestFrame << std::endl;


stbi_image_free(data);
stbi_image_free(data);
}
std::cout << "Done" << std::endl;
}
std::cout << "Done" << std::endl;

}
catch (const std::system_error& exception)
{
std::cerr << "data\\texture\\effect: " << exception.what() << " (" << exception.code() << ")" << std::endl;
}
}
1 change: 0 additions & 1 deletion browedit/BrowEdit.glfw.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "BrowEdit.h"

#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <Version.h>
#include <browedit/Image.h>
Expand Down
1 change: 0 additions & 1 deletion browedit/BrowEdit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include <Windows.h>
#include "Config.h"
#include "MapView.h"
#include <json.hpp>
Expand Down
Loading

0 comments on commit ac0c6fa

Please sign in to comment.