~ fixed shared memory access error

This commit is contained in:
Julian Hinxlage 2019-11-27 11:40:54 +01:00
parent cc7e3e09ad
commit 23b5224946
3 changed files with 8 additions and 2 deletions

View File

@ -75,6 +75,9 @@ namespace vkvm {
} }
auto getSharedMemory() -> char * { auto getSharedMemory() -> char * {
if(impl.sharedMemory != nullptr){
return impl.sharedMemory;
}
int shmId = shmget(impl.sharedMemoryKey, 0, 0); int shmId = shmget(impl.sharedMemoryKey, 0, 0);
if (shmId < 0) { if (shmId < 0) {
//using a local buffer for shared memory testing //using a local buffer for shared memory testing
@ -82,8 +85,10 @@ namespace vkvm {
} }
char *ptr = static_cast<char *>(shmat(shmId, nullptr, 0)); char *ptr = static_cast<char *>(shmat(shmId, nullptr, 0));
if((size_t)ptr == (size_t)-1){ if((size_t)ptr == (size_t)-1){
log(LogLevel::WARNING, strerror(errno));
return getLocalMemory(); return getLocalMemory();
}else{ }else{
impl.sharedMemory = ptr;
return ptr; return ptr;
} }
} }

View File

@ -59,6 +59,7 @@ constexpr int keyboardBufferSize = 16;
int reservedSize = 1024; //NOLINT int reservedSize = 1024; //NOLINT
std::vector<std::function<void()>> eventTable; std::vector<std::function<void()>> eventTable;
bool localMemoryWarn = true; bool localMemoryWarn = true;
char *sharedMemory = nullptr;
}; };
extern Impl impl; extern Impl impl;

View File

@ -22,8 +22,8 @@ namespace vkvm {
setMode(GraphicMode::RGB); setMode(GraphicMode::RGB);
setCharactersPerRow(60);// NOLINT setCharactersPerRow(60);// NOLINT
setCharactersPerColumn(20);// NOLINT setCharactersPerColumn(20);// NOLINT
setHeight(600);// NOLINT setHeight(60);// NOLINT
setWidth(800);// NOLINT setWidth(80);// NOLINT
setMousePosition(42, 42);// NOLINT setMousePosition(42, 42);// NOLINT
setBackgroundColor(black); setBackgroundColor(black);
setForegroundColor(white); setForegroundColor(white);