MISC - Fixed a bug in ResourceLoader
This commit is contained in:
parent
c9c562fda6
commit
cac38decca
|
@ -152,8 +152,10 @@
|
|||
<ClCompile Include="Resource\OResourceHandler.cpp" />
|
||||
<ClCompile Include="Resource\OResource.cpp" />
|
||||
<ClCompile Include="Resource\ResourceManager.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\OysterMutex.cpp" />
|
||||
<ClCompile Include="Thread\OysterThread_Impl.cpp" />
|
||||
|
@ -172,8 +174,10 @@
|
|||
<ClInclude Include="Resource\OysterResource.h" />
|
||||
<ClInclude Include="Resource\OResource.h" />
|
||||
<ClInclude Include="Resource\ResourceManager.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ThreadSafeQueue.h" />
|
||||
<ClInclude Include="Thread\IThreadObject.h" />
|
||||
|
|
|
@ -123,7 +123,7 @@ bool Release(std::map<std::wstring, ResourceData*>& resources, ResourceData* res
|
|||
resource->resource = 0;
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_UNKNOWN:
|
||||
case Oyster::Resource::ResourceType_CUSTOM:
|
||||
resource->unloadFnc(resource->resource);
|
||||
resource->resource = 0;
|
||||
break;
|
||||
|
@ -137,6 +137,13 @@ bool Release(std::map<std::wstring, ResourceData*>& resources, ResourceData* res
|
|||
}
|
||||
ResourceData* Load(/*Out*/ResourceData* targetMem, /*in*/const wchar_t source[], /*in*/ResourceType type)
|
||||
{
|
||||
targetMem->resource = 0;
|
||||
targetMem->loadFnc = 0;
|
||||
targetMem->unloadFnc = 0;
|
||||
targetMem->resourceID = 0;
|
||||
targetMem->resourcetype = type;
|
||||
targetMem->resourceSize = 0;
|
||||
|
||||
std::string sOut;
|
||||
bool success = false;
|
||||
|
||||
|
@ -182,13 +189,20 @@ ResourceData* Load(/*Out*/ResourceData* targetMem, /*in*/const wchar_t source[],
|
|||
}
|
||||
ResourceData* Load(/*Out*/ResourceData* targetMem, /*in*/const wchar_t source[], LoadFunction loadFnc, UnloadFunction unloadFnc)
|
||||
{
|
||||
targetMem->resource = 0;
|
||||
targetMem->loadFnc = 0;
|
||||
targetMem->unloadFnc = 0;
|
||||
targetMem->resourceID = 0;
|
||||
targetMem->resourcetype = ResourceType_CUSTOM;
|
||||
targetMem->resourceSize = 0;
|
||||
|
||||
if(loadFnc)
|
||||
{
|
||||
targetMem->resource = loadFnc(source);
|
||||
if(targetMem->resource)
|
||||
{
|
||||
targetMem->resourceSize = 0;
|
||||
targetMem->resourcetype = ResourceType_UNKNOWN;
|
||||
targetMem->resourcetype = ResourceType_CUSTOM;
|
||||
targetMem->loadFnc = loadFnc;
|
||||
targetMem->unloadFnc = unloadFnc;
|
||||
}
|
||||
|
@ -208,7 +222,7 @@ ResourceData* Reload(std::map<std::wstring, ResourceData*> resources, ResourceDa
|
|||
return Load(resource, filename, resource->loadFnc, resource->unloadFnc);
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_UNKNOWN:
|
||||
case Oyster::Resource::ResourceType_CUSTOM:
|
||||
{
|
||||
resource->unloadFnc(resource->resource);
|
||||
|
||||
|
|
|
@ -29,10 +29,8 @@ namespace Oyster
|
|||
ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */
|
||||
|
||||
ResourceType_COUNT, /**< Handle can be interpeted as ? */
|
||||
|
||||
ResourceType_UNKNOWN = -1, /**< Handle can be interpeted as void* */
|
||||
ResourceType_INVALID = -2, /**< Invalid or non existing resource */
|
||||
ResourceType_CUSTOM, /**< Handle can be interpeted as whatever */
|
||||
ResourceType_INVALID, /**< Handle can be interpeted as whatever */
|
||||
};
|
||||
|
||||
/** A resource handler interface to interact with when loading resources.
|
||||
|
|
Loading…
Reference in New Issue