~ segfault bug fix on getPixel

This commit is contained in:
Julian Hinxlage 2019-11-21 13:03:53 +01:00
parent 511f04edae
commit 82bab57e98

View File

@ -60,18 +60,26 @@ namespace vkvm {
unlockSharedMemory(); unlockSharedMemory();
} }
char *getLocalMemory(){
if (localSharedMemory.empty()) {
constexpr int kilo = 1024;
localSharedMemory.resize(impl.sharedMemorySize);
}
return &localSharedMemory[0];
}
auto getSharedMemory() -> char * { auto getSharedMemory() -> char * {
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
if (localSharedMemory.empty()) { return getLocalMemory();
initSemaphore();
constexpr int kilo = 1024;
localSharedMemory.resize(impl.sharedMemorySize * kilo);
} }
return &localSharedMemory[0]; char *ptr = static_cast<char *>(shmat(shmId, nullptr, 0));
if((size_t)ptr == (size_t)-1){
return getLocalMemory();
}else{
return ptr;
} }
return static_cast<char *>(shmat(shmId, nullptr, 0));
} }
auto getSharedMemory(char *address, int size, int offset) -> void { auto getSharedMemory(char *address, int size, int offset) -> void {