'React Native stops executing
I have the following code
<DocumentPicker
onDone={(res: DocumentPickerResponse[]) => {
if (res.hasOwnProperty('isCancel')) {
} else {
handleDocumentPicker(res);
handleAttachmentResizing();
}
toggleDocumentPicker();
}}
DocumentPicker allows the user to choose a video from their gallery, once they choose the video handleDocumentPicker gets the results array and sets my attachments array state.
handleAttachmentResizing is then called to resize all the video attachments in my attachments state.
This is how the handleAttachmentResizing looks like
const handleAttachmentResizing = async () => {
console.log('handleAttachmentResizing called');
try {
console.log('handleAttachmentResizing called try');
lodash.forEach(newAttachments, async (item, idx) => {
console.log('handleAttachmentResizing called try lodash');
console.log('handleAttachmentResizing loop ', idx);
if (!item.isCompressed && !item.isCompressing && isVideo(item.type)) {
const resizedVideo = await resizeVideo(item, idx);
if (resizedVideo) {
const uri = await moveFile(resizedVideo);
const update: Attachment = {
...item,
isCompressed: true,
isCompressing: false,
uri,
};
updateAttachment(item.uri, update);
}
}
});
} catch (err) {
console.error('handleAttachmentResizing ', err);
}
console.log('handleAttachmentResizing called');
};
And resizeVideo looks like this
const resizeVideo = async (attachment: Attachment, idx: number) => {
console.log('resizeVideo called');
try {
return await Video.compress(
attachment.uri,
{
compressionMethod: 'auto',
getCancellationId: (cancellationId) =>
setVideoCancellationToken(cancellationId),
},
(progress) => {
if(mounted.current){
const updated: Attachment = {
...attachment,
progress,
isCompressing: true,
};
updateAttachment(attachment.uri, updated);
}else {
//Video.cancelCompression()
handleRemoveAttachment(attachment, idx);
}
},
);
} catch (err) {
console.error('resizeVideo ', err);
handleRemoveAttachment(attachment, idx);
}
};
I'm not sure why but handleAttachmentResizing only prints handleAttachmentResizing called try and ends there, if I choose another file in my gallery, it mysteriously continues executing.
Solution 1:[1]
Hackish, assuming
it is the input of the whole network
you might create a new model wrapping conditional CondBatchNorm:
class FedCondBatchNorm2d:
def __init__(self, y, *args, **kwargs):
self.batch_norm = CondBatchNorm2d(*args, **kwargs)
self.cond_img = y
def forward(self, x):
return self.batch_norm(x, self.cond_img)
As its API is now the same as original Reset you might simply switch blocks via module.apply
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Szymon Maszke |
