Skip to content

Commit

Permalink
Fix Android crash
Browse files Browse the repository at this point in the history
  • Loading branch information
elasota committed May 14, 2021
1 parent 71115b2 commit 240ba88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "SDL.h"

#include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
Expand Down Expand Up @@ -70,6 +71,8 @@ GpLogDriver_Android GpLogDriver_Android::ms_instance;

int main(int argc, char* argv[])
{
IGpAllocator *alloc = GpAllocator_C::GetInstance();

SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO);

if (SDL_Init(SDL_INIT_VIDEO) < 0)
Expand All @@ -83,6 +86,7 @@ int main(int argc, char* argv[])
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Android::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Android::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Android::GetInstance());
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);

g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;

Expand All @@ -96,6 +100,7 @@ int main(int argc, char* argv[])
g_gpGlobalConfig.m_osGlobals = &g_gpAndroidGlobals;
g_gpGlobalConfig.m_logger = GpLogDriver_Android::GetInstance();
g_gpGlobalConfig.m_systemServices = GpSystemServices_Android::GetInstance();
g_gpGlobalConfig.m_allocator = alloc;

GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
Expand Down
1 change: 1 addition & 0 deletions AerofoilPortable/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0

# Add your application source files here...
LOCAL_SRC_FILES := \
GpAllocator_C.cpp \
GpThreadEvent_Cpp11.cpp \
GpSystemServices_POSIX.cpp

Expand Down
2 changes: 1 addition & 1 deletion AerofoilPortable/GpAllocator_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void GpAllocator_C::Free(void *buf)
const GpAllocator_C_MMBlock *mmBlock = reinterpret_cast<const GpAllocator_C_MMBlock*>(bytes - GpAllocator_C_MMBlock::AlignedSize());

void *freeLoc = bytes - GpAllocator_C_MMBlock::AlignedSize() - mmBlock->m_offsetFromAllocLocation;
realloc(freeLoc, 0);
(void)realloc(freeLoc, 0);
}

GpAllocator_C *GpAllocator_C::GetInstance()
Expand Down

0 comments on commit 240ba88

Please sign in to comment.